結果
問題 | No.2249 GCDistance |
ユーザー | momoyuu |
提出日時 | 2023-10-24 23:12:13 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,086 ms / 5,000 ms |
コード長 | 1,007 bytes |
コンパイル時間 | 3,166 ms |
コンパイル使用メモリ | 250,676 KB |
実行使用メモリ | 199,720 KB |
最終ジャッジ日時 | 2023-10-24 23:12:47 |
合計ジャッジ時間 | 30,085 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,756 ms
199,720 KB |
testcase_01 | AC | 2,028 ms
199,720 KB |
testcase_02 | AC | 2,062 ms
199,720 KB |
testcase_03 | AC | 2,086 ms
199,720 KB |
testcase_04 | AC | 1,866 ms
199,720 KB |
testcase_05 | AC | 2,077 ms
199,720 KB |
testcase_06 | AC | 2,048 ms
199,720 KB |
testcase_07 | AC | 2,015 ms
199,720 KB |
testcase_08 | AC | 1,749 ms
199,720 KB |
testcase_09 | AC | 2,006 ms
199,720 KB |
testcase_10 | AC | 1,990 ms
199,720 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); const int mx = 1e7; vector<bool> isp(mx+1,0); vector<int> cnt(mx+1,1); vector<int> now(mx+1,0); vector<ll> ans(mx+1,0); vector<int> all(mx+1,0); ans[2] = 1; for(int i = 2;i<=mx;i++){ if(isp[i]==0){ for(int j = i;j<=mx;j+=i){ isp[j] = 1; ll use = i * i; if(j%use!=0) cnt[j] *= -1; else cnt[j] *= 0; } } if(cnt[i]==0) continue; for(int j = i;j<=mx;j+=i){ ll res = j / i; now[j] += res * cnt[i]; } } for(int j = 3;j<=mx;j++){ now[j] += j; ans[j] = ans[j-1]; ans[j] += now[j]; now[j] = j - 1 - now[j]; ans[j] += 2 * now[j]; } int t; cin>>t; while(t--){ int n; cin>>n; cout<<ans[n]<<endl; } }