結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー yamakeyamake
提出日時 2021-08-27 21:36:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 1,915 ms
コンパイル使用メモリ 168,320 KB
実行使用メモリ 15,912 KB
最終ジャッジ日時 2023-08-13 08:12:44
合計ジャッジ時間 3,287 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 40 ms
15,548 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 38 ms
15,356 KB
testcase_13 AC 18 ms
9,712 KB
testcase_14 AC 33 ms
13,952 KB
testcase_15 AC 36 ms
13,972 KB
testcase_16 AC 14 ms
7,928 KB
testcase_17 AC 15 ms
8,804 KB
testcase_18 AC 17 ms
9,248 KB
testcase_19 AC 36 ms
14,364 KB
testcase_20 AC 24 ms
11,220 KB
testcase_21 AC 39 ms
15,912 KB
testcase_22 AC 41 ms
15,744 KB
testcase_23 AC 40 ms
15,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<endl
using lint = long long;
typedef pair<int,int> P;
const bool debugFlag=true;
const lint linf=1e18+7;
const lint inf=1e9+7;
const int MOD=1000000007;
vector<int> sieve(int n){
  vector<int> res,memo(n+1,0);
  for(int i=2;i<=n;++i){
    if(memo[i])continue;
    res.push_back(i);
    for(int j=1;j*i<=n;++j)memo[i*j]=1;
  }
  return res;
}
signed main(){
  lint l,r;cin>>l>>r;
  auto primes=sieve(r*3);
  int res=0;
  for(auto& p:primes){
      if(p/2>=l&&p/2+1<=r){
          if(p>2)++res;
      }
      if(p>=l&&p<=r)++res;
  }
  cout<<res<<"\n";
  return 0;
}
0