Saleh127

UVa 10179

Jun 26th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define fellow_junior ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. ll phi(ll n)
  7. {
  8. ll ans=n;
  9. for(ll i=2;i*i<=n;i++)
  10. {
  11. if(n%i==0)
  12. {
  13. while(n%i==0)
  14. {
  15. n=n/i;
  16. }
  17. ans-=ans/i;
  18. }
  19. }
  20. if(n>1) ans-=ans/n;
  21. return ans;
  22. }
  23.  
  24. int main()
  25. {
  26. fellow_junior
  27.  
  28. ll a;
  29. while(cin>>a && a)
  30. {
  31. cout<<phi(a)<<endl;
  32. }
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment