結果

問題 No.2552 Not Coprime, Not Divisor
ユーザー Yilin FeiYilin Fei
提出日時 2024-01-08 17:42:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 856 bytes
コンパイル時間 1,703 ms
コンパイル使用メモリ 168,432 KB
実行使用メモリ 7,220 KB
最終ジャッジ日時 2024-01-08 17:42:27
合計ジャッジ時間 3,509 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,676 KB
testcase_01 AC 17 ms
6,676 KB
testcase_02 AC 9 ms
6,676 KB
testcase_03 AC 17 ms
6,676 KB
testcase_04 AC 18 ms
6,676 KB
testcase_05 AC 4 ms
6,676 KB
testcase_06 AC 18 ms
6,676 KB
testcase_07 AC 19 ms
6,988 KB
testcase_08 AC 14 ms
6,676 KB
testcase_09 AC 21 ms
7,220 KB
testcase_10 AC 8 ms
6,676 KB
testcase_11 AC 13 ms
6,676 KB
testcase_12 AC 20 ms
7,048 KB
testcase_13 AC 10 ms
6,676 KB
testcase_14 AC 7 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 6 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    assert(1 <= n && n <= 1000000); // Ensure n is within the given bounds

    vector<int> r(n + 1);
    // Initialize r[i] to i for all i
    for(int i = 0; i <= n; i++){
        r[i] = i;
    }
    
    // Calculate the totient function for each number up to n
    for(int i = 2; i <= n; i++){
        if(r[i] != i) continue; // Skip if i is not a prime
        for(int j = i; j <= n; j += i){
            r[j] -= r[j] / i; // Apply the formula for the totient function
        }
    }

    long long ans = 0;
    // Sum up the given function involving the totient for each y from 1 to n
    for(int y = 1; y <= n; y++){
        ans += ((n / y) - 1) * (r[y] - 1);
    }
    cout << ans << endl; 

    return 0;
}
0