結果

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;


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

    long long N, n, ans = 0;
    int i, j, cnt=0, p;
    cin >> N;

    n = pow(N, 1.0 / 2) + 10;

    vector<int> hurui;
    vector<int> res;
    for (i = 0; i < n; i++) {
        hurui.push_back(1);
    }

    for (i = 2; i < n; i++) {
        if (hurui[i - 1] == 1) {
            res.push_back(i);
            cnt += 1;
            for (j = 2*i; j < n; j += i) {
                hurui[j - 1] = -1;
            }
        }
    }

    for (i = 0; i < cnt; i++) {
        p = 2;
        while (pow(res[i], p) <= N) {
            ans += pow(res[i], p);
            p += 1;
        }
    }
    cout << ans << endl;
    return 0;
}
0