結果

問題 No.713 素数の和
ユーザー TakahiroTakahiro
提出日時 2018-07-18 00:50:40
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 511 bytes
コンパイル時間 2,131 ms
コンパイル使用メモリ 51,424 KB
実行使用メモリ 12,056 KB
最終ジャッジ日時 2023-08-18 12:35:33
合計ジャッジ時間 7,391 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:13: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         ans +=N;
         ~~~~^~~

ソースコード

diff #

#include <iostream>

using namespace std;

int getPrime(int maxInt)
{
    if(maxInt == 1) return -1;
    int tmp = maxInt;
    bool flag = 0;
    while(!flag){
        if(tmp < 2) return -1;
        for(int i=2; i<maxInt; --i){
            if(tmp%maxInt) break;
            else flag = true;
        }
        --tmp;
    }
    return tmp;
}

int main()
{
    int N;
    cin >> N;
    int ans;
    while((N = getPrime(N)) != -1){
        ans +=N;
        N-=1;
    }
    cout << ans << endl;
    
    return 0;
}
0