Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- #define brSimp 2000000
- long long SD[brSimp], tst, a, otg,A;
- int used;
- int main(){
- for( int i=2; i<brSimp; i++ ) SD[i] = i;
- for( int i=2; i<brSimp; i++ ){
- if( SD[i] != 0 )
- for(int j= i*2; j<brSimp; j+= SD[i]) SD[j]=0;
- }
- //for( int i=0; i<brSimp; i++ )
- // if( SD[i]!=0 )cout << SD[i] << " ";
- cin >> tst;
- while( tst-- ){
- used = 0;
- otg = 1;
- cin >> a;
- A = a;
- if (((long long)sqrt(A) * (long long )sqrt(A)) == A)
- cout << 1 << endl;
- else {
- //a = (int)sqrt(a);
- for( int i=2; i<=a;){
- while (SD[i] == 0) i++;
- //used = 0;
- if( a%SD[i] == 0 ){
- a/=SD[i];
- if (used == 0){
- otg *= SD[i];
- used = 1;
- //cout << SD[i] << " ";
- }
- //if (a == 1) break;
- }else{
- i++;
- used = 0;
- }
- }
- if (otg == 1) otg *= A;
- else if (((long long)sqrt(A*otg) * (long long )sqrt(A*otg)) != A*otg) otg = A;
- //if (otg == sqrt(A)) otg = 1;
- cout << otg << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment