Given a number N, I need to find if power of biggest prime factor of a number is greater than 1 or not.
N can be as large as 10^18. My approach is as follow :
vector<long long> allfactors;
long long current=2;
while(N>1){
while(N%current==0){
allfactors.push_back(current);
N/=current;
}
current++;
if(current*current > N){
if(N>1){
allfactors.push_back(N);
break;
}
}
}
long long ans=1;
for(int i=allfactors.size()-2;i>=0;i--){
if(allfactors[i]!=allfactors[i+1])
break;
else
ans++;
}
if(ans>1){
cout<<"YES\n";
}
else{
cout<<"NO\n";
}
Can there be better or faster way to do it ? If yes how ? Please help.