結果

問題 No.713 素数の和
ユーザー magmag
提出日時 2020-06-19 00:28:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 579 bytes
コンパイル時間 1,417 ms
コンパイル使用メモリ 164,548 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 12:30:10
合計ジャッジ時間 2,155 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll=long long;
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define rep(i, n) rep2(i,0,n)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int n,cnt=0;cin>>n;
  //$BAG?t$N8D?t(B
  int prime[n];
  //$BAG?t$G$"$k$+(B
  //vector<bool> is_prime(n+1,true);
  bool is_prime[n+1];rep(i,n+1)is_prime[i]=true;
  is_prime[0]=is_prime[1]=false;
  int p=0;
  rep2(i,2,n+1){
    if(is_prime[i]){
      cnt+=i;
      prime[p++]=i;
      for(int j=2*i;j<=n;j+=i)is_prime[j]=false;
    }
  }
  cout<<cnt<<endl;
}
0