結果

問題 No.2552 Not Coprime, Not Divisor
ユーザー t98slider
提出日時 2023-11-29 07:42:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 408 bytes
コンパイル時間 1,948 ms
コンパイル使用メモリ 192,744 KB
最終ジャッジ日時 2025-02-18 02:22:28
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<ll> tb(N + 1);
    ll ans = 0;
    for(int i = N; i >= 2; i--){
        ll c = N / i;
        tb[i] = c * (c - 1) / 2;
        for(int j = 2 * i; j <= N; j += i) tb[i] -= tb[j];
        ans += tb[i] - (c - 1);
    }
    cout << ans << '\n';
}
0