結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー aut_jul_duraut_jul_dur
提出日時 2021-08-27 22:02:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,185 ms / 2,000 ms
コード長 1,326 bytes
コンパイル時間 3,690 ms
コンパイル使用メモリ 234,916 KB
実行使用メモリ 13,780 KB
最終ジャッジ日時 2023-08-13 09:00:02
合計ジャッジ時間 31,003 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,008 ms
13,564 KB
testcase_01 AC 1,009 ms
13,560 KB
testcase_02 AC 1,159 ms
13,696 KB
testcase_03 AC 1,012 ms
13,700 KB
testcase_04 AC 1,008 ms
13,628 KB
testcase_05 AC 1,008 ms
13,572 KB
testcase_06 AC 1,010 ms
13,692 KB
testcase_07 AC 1,009 ms
13,604 KB
testcase_08 AC 1,008 ms
13,684 KB
testcase_09 AC 1,008 ms
13,452 KB
testcase_10 AC 1,008 ms
13,444 KB
testcase_11 AC 1,011 ms
13,780 KB
testcase_12 AC 1,146 ms
13,572 KB
testcase_13 AC 1,063 ms
13,504 KB
testcase_14 AC 1,072 ms
13,452 KB
testcase_15 AC 1,093 ms
13,640 KB
testcase_16 AC 1,029 ms
13,572 KB
testcase_17 AC 1,013 ms
13,504 KB
testcase_18 AC 1,018 ms
13,568 KB
testcase_19 AC 1,156 ms
13,452 KB
testcase_20 AC 1,045 ms
13,444 KB
testcase_21 AC 1,185 ms
13,644 KB
testcase_22 AC 1,010 ms
13,708 KB
testcase_23 AC 1,033 ms
13,672 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