Advertisement
royalsflush

GCJ13 C-small-large1

Apr 14th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. #define MAX_FS 1000010
  6.  
  7. int t; long long a,b;
  8. long long fsq[MAX_FS];
  9. int fs=0;
  10.  
  11. bool isPal(long long x) {
  12.     char tmp[20];
  13.     sprintf(tmp,"%lld",x);
  14.     int l=strlen(tmp);
  15.  
  16.     for (int i=0; i<=l; i++)
  17.         if (tmp[i]!=tmp[l-i-1])
  18.             return false;
  19.     return true;
  20. }
  21.  
  22. void pre() {
  23.     for (long long x=1; x<10000010; x++) {
  24.         if (!isPal(x)) continue;
  25.         if (isPal(x*x))
  26.             fsq[fs++]=x*x;
  27.     }
  28. }
  29.  
  30. int main() {
  31.     pre();
  32.     scanf("%d", &t);
  33.  
  34.     for (int casen=1; casen<=t; casen++) {
  35.         scanf("%lld %lld", &a,&b);
  36.  
  37.         long long* low = lower_bound(fsq,fsq+fs,a);
  38.         long long* up = upper_bound(fsq,fsq+fs,b);
  39.  
  40.         printf("Case #%d: %ld\n", casen,up-low);
  41.     }  
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement