Advertisement
Saleh127

UVA 10490

Sep 25th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. bool prime(ll a)
  6. {
  7. ll c =sqrt(a);
  8. if(a<2) return 0;
  9. if(a==2) return 1;
  10. for(ll i=2;i<=c;i++)
  11. {
  12. if(a%i==0) return 0;
  13. }
  14. return 1;
  15. }
  16.  
  17. int main()
  18. {
  19. ios_base::sync_with_stdio(0);
  20. cin.tie(0);cout.tie(0);
  21.  
  22. ll a,c,d,e,f,i,j,k,l;
  23. while(cin>>a && a)
  24. {
  25. c=prime(a);
  26. d=prime((1LL<<a)-1);
  27. if(c && d)
  28. {
  29. cout<<"Perfect: "<<(1LL<<(a-1))*((1LL<<a)-1)<<"!"<<endl;
  30. }
  31. else if(c && !d)
  32. {
  33. cout<<"Given number is prime. But, NO perfect number is available."<<endl;
  34. }
  35. else
  36. {
  37. cout<<"Given number is NOT prime! NO perfect number is available."<<endl;
  38. }
  39. }
  40.  
  41.  
  42. return 0;
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement