結果

問題 No.2249 GCDistance
ユーザー Nzt3Nzt3
提出日時 2023-03-18 01:10:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,205 ms / 5,000 ms
コード長 566 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 203,116 KB
実行使用メモリ 81,480 KB
最終ジャッジ日時 2023-10-18 16:46:21
合計ジャッジ時間 18,162 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,154 ms
81,480 KB
testcase_01 AC 1,205 ms
81,480 KB
testcase_02 AC 1,183 ms
81,480 KB
testcase_03 AC 1,185 ms
81,480 KB
testcase_04 AC 1,160 ms
81,480 KB
testcase_05 AC 1,193 ms
81,480 KB
testcase_06 AC 1,186 ms
81,480 KB
testcase_07 AC 1,189 ms
81,480 KB
testcase_08 AC 1,144 ms
81,480 KB
testcase_09 AC 1,199 ms
81,480 KB
testcase_10 AC 1,192 ms
81,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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