VasilM

A

Jan 12th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. #define brSimp 2000000
  5.  
  6. long long SD[brSimp], tst, a, otg,A;
  7. int used;
  8. int main(){
  9.    
  10.     for( int i=2; i<brSimp; i++ ) SD[i] = i;
  11.    
  12.     for( int i=2; i<brSimp; i++ ){
  13.          if( SD[i] != 0 )
  14.              for(int j= i*2; j<brSimp; j+= SD[i]) SD[j]=0;
  15.     }
  16.     //for( int i=0; i<brSimp; i++ )
  17.     //     if( SD[i]!=0 )cout << SD[i] << "  ";
  18.    cin >> tst;
  19.    while( tst-- ){
  20.           used = 0;
  21.           otg = 1;
  22.           cin >> a;
  23.           A = a;
  24.           if (((long long)sqrt(A) * (long long )sqrt(A)) == A)
  25.              cout << 1 << endl;
  26.           else {
  27.           //a = (int)sqrt(a);
  28.                 for( int i=2; i<=a;){
  29.                      while (SD[i] == 0) i++;
  30.                       //used = 0;
  31.                      if( a%SD[i] == 0 ){
  32.                          a/=SD[i];
  33.                          if (used == 0){
  34.                             otg *= SD[i];
  35.                             used = 1;
  36.                             //cout << SD[i] << " ";
  37.                             }
  38.                          //if (a == 1) break;        
  39.                      }else{
  40.                            i++;
  41.                            used = 0;
  42.                      }
  43.                 }
  44.                 if (otg == 1) otg *= A;
  45.                 else           if (((long long)sqrt(A*otg) * (long long )sqrt(A*otg)) != A*otg) otg = A;                      
  46.  
  47.                 //if (otg == sqrt(A)) otg = 1;
  48.                 cout << otg << endl;
  49.                 }
  50.    }
  51.    
  52.    return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment