library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub beet-aizu/library

:heavy_check_mark: test/aoj/NTL_1_D.test.cpp

Depends on

Code

// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_D

#include<bits/stdc++.h>
using namespace std;

#define call_from_test
#include "../../math/totient.cpp"
#undef call_from_test

signed main(){
  using ll = long long;
  ll n;
  cin>>n;
  cout<<totient(n)<<endl;
  return 0;
}
#line 1 "test/aoj/NTL_1_D.test.cpp"
// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_D

#include<bits/stdc++.h>
using namespace std;

#define call_from_test
#line 1 "math/totient.cpp"

#line 3 "math/totient.cpp"
using namespace std;
#endif
//BEGIN CUT HERE
template<typename T>
T totient(T n){
  T res=n;
  for(T i=2;i*i<=n;i++){
    if(n%i) continue;
    res=res/i*(i-1);
    while(n%i==0) n/=i;
  }
  if(n!=1) res=res/n*(n-1);
  return res;
}
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif
#line 8 "test/aoj/NTL_1_D.test.cpp"
#undef call_from_test

signed main(){
  using ll = long long;
  ll n;
  cin>>n;
  cout<<totient(n)<<endl;
  return 0;
}
Back to top page