Advertisement
erfanul007

UVa 11064

Mar 13th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef unsigned long long int ull;
  5. typedef long long int ll;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vll;
  8. typedef pair<int,int > pii;
  9. typedef vector< pii > vpii;
  10.  
  11. #define sc scanf
  12. #define pf printf
  13. #define sci(n) scanf("%d",&n)
  14. #define scl(n) scanf("%lld",&n)
  15. #define scf(n) scanf("%lf",&n)
  16. #define scs(s) scanf("%s",s)
  17. #define pfi(n) printf("%d",n)
  18. #define pfl(n) printf("%lld",n)
  19. #define pff(n) cout<<n
  20. #define line printf("\n")
  21. #define spc printf(" ")
  22. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  23. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  24. #define cspf(i) printf("Case %d: ", i)
  25. #define pb push_back
  26. #define mp make_pair
  27. #define ff first
  28. #define ss second
  29. #define all(v) v.begin(),v.end()
  30. #define rall(v) v.rbegin(),v.rend()
  31. #define read() freopen("input.txt", "r", stdin)
  32. #define write() freopen("output.txt", "w", stdout)
  33. /// Constants
  34. #define eps 1e-9
  35. #define inf (1e9)+9
  36. #define PI acos(-1.0) // 3.1415926535897932
  37. #define MAX 1000009
  38.  
  39. bool chk[100009];
  40. vll prime;
  41.  
  42. void seive()
  43. {
  44. memset(chk,0,sizeof(chk));
  45. chk[0]=1;
  46. chk[1]=1;
  47. for(int i=2;i<=100000;i++){
  48. if(chk[i]){
  49. continue;
  50. }
  51. prime.pb((ll)i);
  52. for(int j=2;i*j<=100000;j++){
  53. chk[i*j]=1;
  54. }
  55. }
  56. }
  57.  
  58. ll phidiv(ll n)
  59. {
  60. ll div=1;
  61. ll result=n;
  62. ll ans = n;
  63. bool flg=0;
  64. for(int i=0;prime[i]*prime[i]<=n;i++){
  65. if(n%prime[i]==0){
  66. flg=1;
  67. int cnt=1;
  68. while(n%prime[i]==0){
  69. n/=prime[i];
  70. cnt++;
  71. }
  72. div*=cnt;
  73. result-=result/prime[i];
  74. }
  75. }
  76. if(n>1){
  77. div*=2;
  78. result-=result/n;
  79. }
  80. div--;
  81. ans = ans-(result+div);
  82. return ans;
  83. }
  84.  
  85. int main()
  86. {
  87. seive();
  88. ll n;
  89. while(cin>>n && n){
  90. ll ans = phidiv(n);
  91. cout<<ans<<endl;
  92. }
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement