#include <iostream>
#include <vector>
#include <bitset>
#include <cmath>
using namespace std;
bitset<10000000> p;
vector<int> prime;
int tmp;
void calc(){
tmp=sqrt(1e7);
for(int i=2;i<1e7;i++){
if(!p[i]){
prime.push_back(i);
if(i<=tmp)
for(int j=i*i;j<1e7;j+=i)
p[j]=1;
}
}
}
int main(){
ios::sync_with_stdio(0);
calc();
long long n;
while(cin>>n&&n){
if(n<0)
n*=-1;
long long int ans=-2,flag=0;
int j=0;
tmp=sqrt(n);
while(j<prime.size()&&prime[j]<=tmp&&n>1){
if(n%prime[j]==0){
if(ans==-2)
ans=prime[j],flag++;
else if(ans!=prime[j]){
ans=prime[j];
flag++;
}
n/=prime[j];
}
else
j++;
}
if(flag>0&&n>ans)
ans=n,flag++;
if(flag<2)
cout<<-1<<endl;
else
cout<<ans<<endl;
}
}
#include <vector>
#include <bitset>
#include <cmath>
using namespace std;
bitset<10000000> p;
vector<int> prime;
int tmp;
void calc(){
tmp=sqrt(1e7);
for(int i=2;i<1e7;i++){
if(!p[i]){
prime.push_back(i);
if(i<=tmp)
for(int j=i*i;j<1e7;j+=i)
p[j]=1;
}
}
}
int main(){
ios::sync_with_stdio(0);
calc();
long long n;
while(cin>>n&&n){
if(n<0)
n*=-1;
long long int ans=-2,flag=0;
int j=0;
tmp=sqrt(n);
while(j<prime.size()&&prime[j]<=tmp&&n>1){
if(n%prime[j]==0){
if(ans==-2)
ans=prime[j],flag++;
else if(ans!=prime[j]){
ans=prime[j];
flag++;
}
n/=prime[j];
}
else
j++;
}
if(flag>0&&n>ans)
ans=n,flag++;
if(flag<2)
cout<<-1<<endl;
else
cout<<ans<<endl;
}
}
Comments
Post a Comment