結果

問題 No.2249 GCDistance
ユーザー Nzt3Nzt3
提出日時 2023-03-18 01:16:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 473 ms / 5,000 ms
コード長 544 bytes
コンパイル時間 2,024 ms
コンパイル使用メモリ 203,956 KB
実行使用メモリ 120,384 KB
最終ジャッジ日時 2023-10-18 16:48:02
合計ジャッジ時間 9,009 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 404 ms
120,384 KB
testcase_01 AC 467 ms
120,384 KB
testcase_02 AC 461 ms
120,384 KB
testcase_03 AC 463 ms
120,384 KB
testcase_04 AC 430 ms
120,384 KB
testcase_05 AC 466 ms
120,384 KB
testcase_06 AC 473 ms
120,384 KB
testcase_07 AC 465 ms
120,384 KB
testcase_08 AC 414 ms
120,384 KB
testcase_09 AC 472 ms
120,384 KB
testcase_10 AC 463 ms
120,384 KB
権限があれば一括ダウンロードができます

ソースコード

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