結果

問題 No.713 素数の和
ユーザー hiro_ei1812
提出日時 2019-09-14 18:49:00
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 561 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 54,360 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-06 09:51:10
合計ジャッジ時間 829 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#define True 1
int sosuu(int N);
using namespace std;

int main(){
    int N;
    int i,ans=2;
    
    cin>>N;   //N以下の素数の範囲を示す

    if(N==2){
        cout<<"2"<<endl;
        return(0);
    }
    else if(N<2){
        cout<<"0"<<endl;
        return(0);
    }

    for(i=3;i<=N;i+=2){
        if(sosuu(i)==0){
            ans+=i;
        }
    }
    cout<<ans<<endl;

    return(0);
}

int sosuu(int N){
    int k;
    int n=0;

    for(k=3;k<=N && (N%k)!=0;k+=2);

    if(N<=k) return n ;
    else     return n+1;
}
0