結果

問題 No.2249 GCDistance
ユーザー CleyLCleyL
提出日時 2023-07-06 15:00:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,374 ms / 5,000 ms
コード長 615 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 73,796 KB
実行使用メモリ 159,520 KB
最終ジャッジ日時 2023-09-27 16:01:30
合計ジャッジ時間 17,211 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,051 ms
159,520 KB
testcase_01 AC 1,374 ms
159,304 KB
testcase_02 AC 1,354 ms
159,312 KB
testcase_03 AC 1,356 ms
159,364 KB
testcase_04 AC 1,147 ms
159,220 KB
testcase_05 AC 1,366 ms
159,464 KB
testcase_06 AC 1,339 ms
159,304 KB
testcase_07 AC 1,309 ms
159,304 KB
testcase_08 AC 1,017 ms
159,260 KB
testcase_09 AC 1,328 ms
159,260 KB
testcase_10 AC 1,308 ms
159,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

vector<long long> phi_table(long long n){
  vector<long long> ret(n);
  for(int i = 0; n > i; i++){
    ret[i] = i;
  }
  for(int i = 2; n >= i; i++){
    if(ret[i] == i){
      for(int j = i; n >= j; j+=i){
        ret[j] = ret[j]/i*(i-1);
      }
    }
  }
  return ret;
}

int main(){
  int q;cin>>q;
  auto z = phi_table(10000001);
  vector<long long> cz(10000002);
  for(int i = 1; 10000002 > i; i++){
    cz[i] = cz[i-1] + max(0LL,i-(z[i]+1));
  }
  for(int i = 0; q > i; i++){
    long long n;cin>>n;
    cout << n*(n-1)/2 + cz[n] << endl;
  }

}
0