Advertisement
a53

maxprimeintreele

a53
Dec 20th, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. int Phi(int n)
  5. {
  6. int d;
  7. unsigned long long int nrp=n,prod=1;
  8. if(n%2==0)
  9. {
  10. while(n%2==0)
  11. n/=2;
  12. nrp*=(2-1),prod*=2;
  13. }
  14. d=3;
  15. while(n>1)
  16. {
  17. if(n%d==0)
  18. {
  19. while(n%d==0)
  20. n/=d;
  21. nrp*=d-1,prod*=d;
  22. }
  23. else
  24. d+=2;
  25. if(n>1&&d*d>n)
  26. {
  27. nrp*=n-1,prod*=n;
  28. break;
  29. }
  30. }
  31. return (int) (nrp/prod);
  32. }
  33.  
  34. int main()
  35. {
  36. int x,sol;
  37. long double Max=0;
  38. ifstream f("maxprimeintreele.in");
  39. while(f>>x)
  40. {
  41. long double t=Phi(x);
  42. if(1.0*x/t>Max)
  43. Max=1.0*x/t,sol=x;
  44. }
  45. ofstream g("maxprimeintreele.out");
  46. g<<sol;
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement