結果

問題 No.2249 GCDistance
ユーザー 👑 NachiaNachia
提出日時 2023-03-17 21:42:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 432 ms / 5,000 ms
コード長 994 bytes
コンパイル時間 707 ms
コンパイル使用メモリ 79,768 KB
実行使用メモリ 82,776 KB
最終ジャッジ日時 2023-10-18 14:13:31
合計ジャッジ時間 7,271 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 383 ms
81,456 KB
testcase_01 AC 425 ms
82,776 KB
testcase_02 AC 419 ms
82,776 KB
testcase_03 AC 426 ms
82,776 KB
testcase_04 AC 402 ms
81,984 KB
testcase_05 AC 426 ms
82,776 KB
testcase_06 AC 427 ms
82,776 KB
testcase_07 AC 428 ms
82,776 KB
testcase_08 AC 373 ms
81,456 KB
testcase_09 AC 432 ms
82,776 KB
testcase_10 AC 412 ms
82,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;


int main(){
    int T; cin >> T;
    vector<i64> N(T); rep(t,T) cin >> N[t];
    i64 maxN = *max_element(N.begin(), N.end());
    vector<i64> A(maxN+1, 1);
    A[0] = A[1] = 0;
    for(i64 p=2; p<=maxN; p++) if(p == 2 || (p % 2 != 0 && A[p] == 1)){
        for(i64 q=p; q<=maxN; q+=p) A[q] *= p-1;
        for(i64 pp=p*p; pp<=maxN; pp*=p) for(i64 q=pp; q<=maxN; q+=pp) A[q] *= p;
    }
    rep(i,maxN) A[i+1] += A[i];
    for(i64 n : N) cout << (n*(n-1) - A[n]) << '\n';
    return 0;
}



struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;

0