結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー aut_jul_duraut_jul_dur
提出日時 2021-08-27 22:02:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,199 ms / 2,000 ms
コード長 1,326 bytes
コンパイル時間 4,072 ms
コンパイル使用メモリ 236,068 KB
実行使用メモリ 13,796 KB
最終ジャッジ日時 2024-05-01 02:36:11
合計ジャッジ時間 31,033 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,010 ms
13,792 KB
testcase_01 AC 1,009 ms
13,796 KB
testcase_02 AC 1,169 ms
13,664 KB
testcase_03 AC 1,011 ms
13,668 KB
testcase_04 AC 1,008 ms
13,664 KB
testcase_05 AC 1,011 ms
13,788 KB
testcase_06 AC 1,010 ms
13,664 KB
testcase_07 AC 1,026 ms
13,664 KB
testcase_08 AC 1,009 ms
13,660 KB
testcase_09 AC 1,010 ms
13,664 KB
testcase_10 AC 1,009 ms
13,668 KB
testcase_11 AC 1,011 ms
13,664 KB
testcase_12 AC 1,152 ms
13,664 KB
testcase_13 AC 1,069 ms
13,792 KB
testcase_14 AC 1,078 ms
13,792 KB
testcase_15 AC 1,104 ms
13,664 KB
testcase_16 AC 1,039 ms
13,664 KB
testcase_17 AC 1,014 ms
13,664 KB
testcase_18 AC 1,021 ms
13,660 KB
testcase_19 AC 1,170 ms
13,664 KB
testcase_20 AC 1,050 ms
13,684 KB
testcase_21 AC 1,199 ms
13,664 KB
testcase_22 AC 1,010 ms
13,660 KB
testcase_23 AC 1,028 ms
13,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
const long long INF = 9*1e18;
using ll = long long;
using mint = modint1000000007;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
long double PI = 3.14159265358979;
vector<ll> primelist;

bool Prime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

void primeinput(){
  for(ll i = 2;i<2002000;i++){
    if(Prime(i)){
      primelist.push_back(i);
    }
  }
}





int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  primeinput();
  map<ll,ll> P;
  rep(i,primelist.size()){
    P[primelist[i]]++;
  }
  ll L,R;
  cin>>L>>R;
  ll ans = 0;
  for(int i = L;i<=R;i++){
    if(P.count(i)){
      ans++;
    }
    if(i != L){
      if(P.count(i+i-1)){
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
0