Saleh127

spoj ETF (totient)

Jul 8th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 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. int phi(int n)
  7. {
  8. int re=n;
  9. for(int i=2;i*i<=n;i++)
  10. {
  11. if(n%i==0)
  12. {
  13. while(n%i==0)
  14. {
  15. n/=i;
  16. }
  17. re-=(re/i);
  18. }
  19. }
  20. if(n>1) re-=(re/n);
  21. return re;
  22. }
  23. int main()
  24. {
  25. fellow_junior
  26.  
  27. test
  28. {
  29. ll a,c,d,f,i,j,k,l;
  30. cin>>a;
  31. cout<<phi(a)<<endl;
  32. }
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment