結果

問題 No.2249 GCDistance
ユーザー Nzt3
提出日時 2023-03-18 01:16:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 389 ms / 5,000 ms
コード長 544 bytes
コンパイル時間 2,088 ms
コンパイル使用メモリ 195,128 KB
最終ジャッジ日時 2025-02-11 14:43:36
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int mod=998244353;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  vector<int>phi((int)1e7+10);
  iota(phi.begin(),phi.end(),0);
  for(int i=2;i<(int)1e7+10;i++){
    if(phi[i]!=i)continue;
    for(int j=i;j<(int)1e7+10;j+=i){
      phi[j]=phi[j]/i*(i-1);
    }
  }
  vector<long long>ans((int)1e7+10);
  for(int i=2;i<(int)1e7+9;i++){
    ans[i]+=(i-1)*2-phi[i];
    ans[i+1]+=ans[i];
  }
  int T;
  cin>>T;
  while(T--){
    int N;
    cin>>N;
    cout<<ans[N]<<'\n';
  }
}
0