tcbpg

SPOJ Twosqrs

Oct 24th, 2011
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cmath>
  3. #include <cstring>
  4.  
  5. typedef long long tint;
  6.  
  7. const int SIZE = 1000001;
  8. tint primos[80000],factor[1024],mult[1024];
  9. int P,F;
  10.  
  11. char _criba[SIZE];
  12.  
  13. void criba(){
  14.     P = 0;
  15.     memset(_criba,0,sizeof(_criba));
  16.    
  17.     for(int k = 2; k < SIZE; k++){
  18.         if(!_criba[k]){
  19.             primos[P++] = k;
  20.             for(int j = 2*k; j < SIZE; j+=k)
  21.                 _criba[j] = 1;
  22.         }
  23.     }
  24. }
  25.  
  26. void factorear(tint x){    
  27.     bool once,found = false;
  28.    
  29.     for(int i = 0; i < P && primos[i]*primos[i] <= x; i++){
  30.         once = false;
  31.         while(x % primos[i] == 0){
  32.             found = true;
  33.             if(!once){
  34.                 factor[F] = primos[i], mult[F++] = 0;
  35.                 once = true;
  36.             }
  37.            
  38.             mult[F-1]++;
  39.             x = x/primos[i];
  40.         }
  41.     }
  42.    
  43.     if(!found) factor[F] = x, mult[F++] = 1; else factorear(x);
  44. }
  45.  
  46. int main(){
  47. #ifdef ACM
  48.     freopen("test.in","r",stdin);
  49. #endif
  50.     criba();
  51.  
  52.     int t; scanf("%d\n", &t);
  53.     tint val;
  54.    
  55.     while(t-- > 0){
  56.         scanf("%lld\n",&val);
  57.        
  58.         factor[0] = 1, F = 0;
  59.  
  60.         factorear(val);
  61.         bool ok = true;
  62.        
  63.         for(int i = 0; i < F; i++)
  64.             ok = ok && !(factor[i] % 4 == 3 && mult[i] % 2 == 1);
  65.    
  66.         if(ok) printf("Yes\n"); else printf("No\n");
  67.     }
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment