結果

問題 No.3296 81-like number
ユーザー toufu24
提出日時 2025-10-05 13:37:55
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,259 bytes
コンパイル時間 4,161 ms
コンパイル使用メモリ 335,084 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-05 13:39:38
合計ジャッジ時間 5,051 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define all(v) v.begin(), v.end()
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort(v.rbegin(), v.rend())
#define REVERSE(v) reverse(v.begin(), v.end())
#define ll long
#define ld long double

#define int ll

// 1 以上 N 以下の整数が素数かどうかを返す
vector<bool> Eratosthenes(int N) {
    // テーブル
    vector<bool> isprime(N + 1, true);

    // 0, 1 は予めふるい落としておく
    isprime[0] = isprime[1] = false;

    // ふるい
    for (int p = 2; p <= N; ++p) {
        // すでに合成数であるものはスキップする
        if (!isprime[p]) continue;

        // p 以外の p の倍数から素数ラベルを剥奪
        for (int q = p * 2; q <= N; q += p) {
            isprime[q] = false;
        }
    }

    // 1 以上 N 以下の整数が素数かどうか
    return isprime;
}

int32_t main() {
    int n;
    cin >> n;
    auto isprime = Eratosthenes(1e6 + 100);
    int ans = 0;
    for (int i = 0; i < isprime.size(); i++) {
        if (isprime[i]) {
            for (int j = i * i; j <= n; j *= i) {
                ans += j;
            }
        }
    }
    cout << ans << endl;
}
0