Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
- vector<long long>prime;
- bool x[10000007];
- void seieve()
- {
- x[0]=1;
- x[1]=1;
- prime.push_back(2);
- for(int i=3; i*i<=10000005; i+=2)
- {
- if(!x[i])
- {
- for(int j=i*i; j<=10000005; j+=2*i)
- {
- x[j]=1;
- }
- }
- }
- for(int i=3; i<=10000005; i+=2)
- if(!x[i])
- prime.push_back(i);
- }
- int main()
- {
- //fastio;
- //freopen("in.txt","r",stdin);
- //freopen("out.txt","w",stdout);
- seieve();
- long long a,b,c,d,i,j,n,m;
- cin>>n;
- while(n)
- {
- n=abs(n);
- a=0;
- b=-1;
- m=n;
- c=0;
- while(a<prime.size()&&n>1&&prime[a]*prime[a]<=n)
- {
- if(n%prime[a]==0)
- c++;
- while(n%prime[a]==0)
- {
- b=max(b,prime[a]);
- n/=prime[a];
- }
- a++;
- }
- if(n>1&&m!=n)
- {
- c++;
- b=max(b,n);
- }
- if(c<=1)
- b=-1;
- cout<<b<<'\n';
- cin>>n;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement