# UVa 10622 (GCD decomposition factorization) Perfect p-th Powers

Source: Internet
Author: User

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

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.