結果

問題 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  
実行時間 42 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 1,781 ms
コンパイル使用メモリ 169,032 KB
実行使用メモリ 16,152 KB
最終ジャッジ日時 2024-05-01 01:53:24
合計ジャッジ時間 2,891 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 42 ms
15,864 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 37 ms
15,600 KB
testcase_13 AC 20 ms
9,808 KB
testcase_14 AC 31 ms
14,024 KB
testcase_15 AC 33 ms
14,208 KB
testcase_16 AC 14 ms
8,180 KB
testcase_17 AC 17 ms
8,904 KB
testcase_18 AC 17 ms
9,428 KB
testcase_19 AC 35 ms
14,720 KB
testcase_20 AC 26 ms
11,620 KB
testcase_21 AC 41 ms
16,152 KB
testcase_22 AC 41 ms
16,152 KB
testcase_23 AC 40 ms
16,036 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