Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int prime(int n){
- int j,flag=0;
- int sq=sqrt(n);
- for(j=2;j<=sq;j++)
- {
- if(n%j==0){
- {flag=1;
- break;}
- }}
- if(flag==0)
- return 1;
- else
- return 0;
- }
- int main()
- {while(1){
- int num;
- scanf("%d",&num);
- if(num==0)
- return 0;
- int i,ans=0;
- if(num%2==0)
- ans=2;
- for(i=3;i<=num;i+=2)
- {
- if(prime(i))
- {
- if(num%i==0&&num!=i)
- ans=i;
- }
- }
- if(ans==0 || num==2)
- ans=-1;
- printf("%d\n",ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement