結果

問題 No.2249 GCDistance
ユーザー Shreyan RayShreyan Ray
提出日時 2023-03-17 22:22:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,454 ms / 5,000 ms
コード長 1,421 bytes
コンパイル時間 3,863 ms
コンパイル使用メモリ 193,408 KB
最終ジャッジ日時 2025-02-11 13:30:15
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define f first
#define s second
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1e7 + 69;
int sieve[maxn];
int tot[maxn];
int dp[maxn];
void pre()
{
tot[1] = 0;
for (int i=2; i<maxn; i++){
tot[i] = 1;
}
for (int i=2; i<maxn; i++){
if (sieve[i]!=0) continue;
tot[i] = i-1;
for (int j = i+i; j<maxn; j+=i){
sieve[j] = i;
int copy = j;
int val = i - 1;
while (copy%i==0){
val *= i;
copy/=i;
}
val/=i;
tot[j] *= val;
}
}
for (int i=1; i<maxn; i++){
dp[i] = dp[i-1];
dp[i] += tot[i] * 1 + (i-1-tot[i]) * 2;
}
}
void Solve()
{
int n; cin>>n;
cout<<dp[n]<<"\n";
}
int32_t main()
{
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
pre();
cin >> t;
for(int i = 1; i <= t; i++)
{
//cout << "Case #" << i << ": ";
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0