Advertisement
Md_hosen_zisad

LARGEST PRIME DIVISOR

Nov 21st, 2017
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. #include<stdio.h>
  2. int prime(int n){
  3. int j,flag=0;
  4. int sq=sqrt(n);
  5. for(j=2;j<=sq;j++)
  6. {
  7.     if(n%j==0){
  8.         {flag=1;
  9.     break;}
  10. }}
  11. if(flag==0)
  12. return 1;
  13. else
  14.     return 0;
  15.  
  16. }
  17.  
  18. int main()
  19. {while(1){
  20. int num;
  21. scanf("%d",&num);
  22. if(num==0)
  23.     return 0;
  24. int i,ans=0;
  25. if(num%2==0)
  26.     ans=2;
  27. for(i=3;i<=num;i+=2)
  28. {
  29.     if(prime(i))
  30.     {
  31.         if(num%i==0&&num!=i)
  32.             ans=i;
  33.     }
  34. }
  35. if(ans==0 || num==2)
  36.  
  37.  ans=-1;
  38. printf("%d\n",ans);
  39. }
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement