Test instructions
For a 32-bit signed integer x, write it in the form x = BP, and ask for the maximum possible value of P.
Analysis:
The x is decomposed factorization, and then the GCD of all exponents is calculated.
For negative numbers to be processed again, the negative number of p must be an odd number to line.
1#include <cstdio>2#include <cmath>3 4 Const intMAXN =46500;5 BOOLVIS[MAXN +Ten];6 intprime[4810], CNT =1;7 8 voidInit ()9 {Ten intm = sqrt (MAXN +0.5); One for(inti =2; I <= m; ++i)if(!Vis[i]) A for(intj = i * I; J <= Maxn; J + = i) vis[j] =true; - for(inti =2; I <= MAXN; ++i)if(!vis[i]) prime[cnt++] =i; -cnt--; the } - - intgcdintAintb) - { + returnb = =0? A:GCD (b, a%b); - } + A intSolveintN) at { - intAns =0; - for(inti =1; I <= CNT; ++i) - { - intK =0; - while(n% prime[i] = =0) in { -k++; toN/=Prime[i]; + } - if(k) the { * if(k = =1)return 1; $Ans =gcd (k, ans);Panax Notoginseng } - } the if(N >1)return 1; + returnans; A } the + intMain () - { $ Init (); $ - intN; - while(SCANF ("%d", &n) = =1&&N) the { - intans = Solve (n <0? -( n);Wuyi if(N <0) while(Ans &1) ==0) Ans >>=1; theprintf"%d\n", ans); - } Wu - return 0; About}
code June
UVa 10622 (GCD decomposition factorization) Perfect p-th Powers