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/2286.test.cpp

Depends on

Code

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

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

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

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  const int MAX = 1e6;
  auto ts=totient_table(MAX);
  vector<long long> sm(ts.begin(),ts.end());
  for(int i=0;i<MAX;i++) sm[i+1]+=sm[i];

  int t;
  cin>>t;
  for(int i=0;i<t;i++){
    int n;
    cin>>n;
    cout<<sm[n]+1<<"\n";
  }
  cout<<flush;
  return 0;
}
#line 1 "test/aoj/2286.test.cpp"
// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2286

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

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

#line 3 "math/totient_table.cpp"
using namespace std;
#endif
//BEGIN CUT HERE
vector<int> totient_table(int n){
  vector<int> ts(n+1);
  iota(ts.begin(),ts.end(),0);
  for(int i=2;i<=n;i++){
    if(ts[i]!=i) continue;
    for(int j=i;j<=n;j+=i) ts[j]=ts[j]/i*(i-1);
  }
  return ts;
}
//END CUT HERE
#ifndef call_from_test
//INSERT ABOVE HERE
signed main(){
  return 0;
}
#endif
#line 8 "test/aoj/2286.test.cpp"
#undef call_from_test

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  const int MAX = 1e6;
  auto ts=totient_table(MAX);
  vector<long long> sm(ts.begin(),ts.end());
  for(int i=0;i<MAX;i++) sm[i+1]+=sm[i];

  int t;
  cin>>t;
  for(int i=0;i<t;i++){
    int n;
    cin>>n;
    cout<<sm[n]+1<<"\n";
  }
  cout<<flush;
  return 0;
}
Back to top page