a53

DivizoriPrimi

a53
Jan 2nd, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5.  
  6. int prim(long long x)
  7. {
  8. long long i;
  9. if(x==1 || x==0)
  10. return 0;
  11. for(i=2;i*i<x;i++)
  12. if(x%i==0)
  13. return 0;
  14. if(i*i==x)
  15. return 0;
  16. return 1;
  17. }
  18.  
  19. int main()
  20. {
  21. unsigned long long i,j,n,ok=0,x,s=0;
  22. cin>>n;
  23. for(i=1;i<=n;i++)
  24. {
  25. cin>>x;
  26. ok=0;
  27. if(prim(x)==1)
  28. s+=x;
  29. else
  30. {
  31. for(j=1;j*j<=x && ok==0;j++)
  32. if(x%j==0 && prim(j)==1)
  33. {
  34. ok=1;
  35. s+=j;
  36. }
  37. }
  38. }
  39. cout<<s;
  40. return 0;
  41. }
Add Comment
Please, Sign In to add comment