結果

問題 No.2249 GCDistance
ユーザー momoyuu
提出日時 2023-10-24 23:12:13
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,075 ms / 5,000 ms
コード長 1,007 bytes
コンパイル時間 2,783 ms
コンパイル使用メモリ 249,600 KB
実行使用メモリ 199,800 KB
最終ジャッジ日時 2024-09-24 18:15:13
合計ジャッジ時間 28,794 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#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;
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0