結果

問題 No.3296 81-like number
コンテスト
ユーザー Tyto alba
提出日時 2025-11-04 00:48:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 915 ms
コンパイル使用メモリ 88,032 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-11-04 00:48:03
合計ジャッジ時間 2,826 ms
ジャッジサーバーID
(参考情報)
judge1 / judge7
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    int64_t n, ans=0;
    int i, j, k;
    bool flg = true;
    vector<int> sosu;

    cin >> n;

    int n_ma = sqrt(n);
    for (i=2; i<=n_ma; i++) {
        if (i == 2){
            sosu.push_back(i);
            k = 2;
            while (pow(i, k) <= n) {
                ans += pow(i, k);
                k++;
            }
            continue;
        }

        for (j=0; j<sosu.size(); j++) {
            if (i % sosu[j] == 0) {
                flg = false;
                break;
            }
        }

        if (flg) {
            sosu.push_back(i);
            k = 2;
            while (pow(i, k) <= n) {
                ans += pow(i, k);
                k++;
            }
            
        }
        flg = true;
    }

    cout << ans << endl;
}
0