結果

問題 No.2249 GCDistance
ユーザー Shreyan RayShreyan Ray
提出日時 2023-03-17 22:22:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,324 ms / 5,000 ms
コード長 1,421 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 202,356 KB
実行使用メモリ 238,212 KB
最終ジャッジ日時 2023-10-18 15:19:06
合計ジャッジ時間 31,343 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,253 ms
238,204 KB
testcase_01 AC 2,291 ms
238,212 KB
testcase_02 AC 2,324 ms
238,212 KB
testcase_03 AC 2,319 ms
238,212 KB
testcase_04 AC 2,253 ms
238,212 KB
testcase_05 AC 2,300 ms
238,212 KB
testcase_06 AC 2,303 ms
238,212 KB
testcase_07 AC 2,310 ms
238,212 KB
testcase_08 AC 2,246 ms
238,212 KB
testcase_09 AC 2,281 ms
238,212 KB
testcase_10 AC 2,287 ms
238,212 KB
権限があれば一括ダウンロードができます

ソースコード

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;
}
0