Advertisement
a53

Factori4

a53
Jan 30th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int nr_div(int n)
  6. {
  7. int p=0;
  8. if(n%2==0)
  9. {
  10. ++p;
  11. while(n%2==0)
  12. n=n/2;
  13. }
  14. int d=3;
  15. while(n>1)
  16. {
  17. if(n%d==0)
  18. {
  19. ++p;
  20. if(p>1)
  21. return 2;
  22. while(n%d==0)
  23. n=n/d;
  24. }
  25. else
  26. d+=2;
  27. }
  28. if(n>1&&d*d>n)
  29. ++p;
  30. return p;
  31. }
  32.  
  33. int main()
  34. {
  35. int n;
  36. cin>>n;
  37. int a[n];
  38. for(int i=0;i<n;++i)
  39. cin>>a[i];
  40. sort(a,a+n);
  41. for(int i=0;i<n;++i)
  42. if(nr_div(a[i])==1)
  43. {
  44. cout<<a[i];
  45. return 0;
  46. }
  47. cout<<"NU EXISTA";
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement