結果

問題 No.3691 Calculate Mu Sum
コンテスト
ユーザー GOTKAKO
提出日時 2026-09-14 19:18:31
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 193 ms / 2,000 ms
+ 184µs
コード長 672 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,206 ms
コンパイル使用メモリ 214,276 KB
実行使用メモリ 43,648 KB
最終ジャッジ日時 2026-09-14 19:18:36
合計ジャッジ時間 3,630 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

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

    int N; cin >> N;
    int Need = N;
    vector<bool> prime(Need+1,true);
    prime.at(0) = false; prime.at(1) = false;
    for(int i=2; i*i<=Need; i++){
        if(!prime.at(i)) continue;
        for(int k=i*i; k<=Need; k+=i) prime.at(k) = false;
    }
    vector<int> V(N+1,1);
    V.at(0) = 0;
    for(long long p=2; p<=N; p++) if(prime.at(p)){
        for(long long i=p; i<=N; i+=p) V.at(i) = -V.at(i);
        long long p2 = p*p;
        for(long long i=p2; i<=N; i+=p2) V.at(i) = 0;
    }

    cout << accumulate(V.begin(),V.end(),0) << endl;
}
0