結果
| 問題 | No.2552 Not Coprime, Not Divisor | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-01-08 17:42:24 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 21 ms / 2,000 ms | 
| コード長 | 856 bytes | 
| コンパイル時間 | 1,606 ms | 
| コンパイル使用メモリ | 169,352 KB | 
| 実行使用メモリ | 7,244 KB | 
| 最終ジャッジ日時 | 2024-09-27 19:37:45 | 
| 合計ジャッジ時間 | 2,904 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 | 
ソースコード
#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;
}
            
            
            
        