给出 n, 写成 n= x^p 的形式,求p最大值
#include <iostream> #include <vector> #include <cmath> #include <algorithm> using namespace std ; #define int long long int flg =0 ; int gcd(int x,int y){ return y==0?x:gcd(y,x%y); } void sov(int x){ vector<int> b; int i; for(i=2;i*i<=x;i++){ if(x%i==0){ int t=0; while(x%i==0) t++,x/=i; b.push_back(t); } } if(x>1){ cout<<1<<endl; return ; } int ans=b[0]; for(i=1;i<b.size();i++) ans=__gcd(b[i],ans); if(flg){ while(ans%2==0) ans/=2; } cout<<ans<<'\n'; } signed main(){ int x; while(cin>>x,x){ flg=0 ; if(x<0) flg=1; x=abs(x); sov(x); } }
标签:Perfect,gcd,int,long,th,UVA,10622,include From: https://www.cnblogs.com/towboa/p/17304616.html