Advertisement
vfonic

Untitled

Apr 14th, 2013
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cctype>
  3. #include <climits>
  4. #include <cmath>
  5. #include <cstdio>
  6. #include <cstdlib>
  7. #include <cstring>
  8. #include <iostream>
  9. #include <list>
  10. #include <map>
  11. #include <queue>
  12. #include <set>
  13. #include <sstream>
  14. #include <string>
  15. #include <vector>
  16.  
  17. #define inf 1000000000
  18. #define MAXN 100000
  19.  
  20. using namespace std;
  21.  
  22. bool is_palindrome(long long x) {
  23.     long long tmp_x = x;
  24.     long long x_reversed = 0;
  25.     while (tmp_x) {
  26.         int digit = tmp_x%10;
  27.         x_reversed = x_reversed*10 + digit;
  28.         tmp_x/=10;
  29.     }
  30.    
  31.     return x == x_reversed;
  32. }
  33.  
  34. long long next_palindrome(long long x) {
  35.     ++x;
  36.     while (!is_palindrome(x)) {
  37.         ++x;
  38.     }
  39.     return x;
  40. }
  41.  
  42. int main()
  43. {
  44.     int t;
  45.     scanf("%d\n", &t);
  46.    
  47.     for (int qwertz = 0; qwertz < t; ++qwertz) {
  48.         long long a, b;
  49.         scanf("%lld%lld", &a, &b);
  50.        
  51.         long long hi = sqrt(b);
  52.         for (long long i = 1; i <= hi; i = next_palindrome(i)) {
  53.             if (is_palindrome(i*i)) {
  54.                 printf("fair number:%lld root:%lld\n", i*i, i);
  55.             }
  56.         }
  57.         printf("\n");
  58.     }
  59.    
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement