結果
問題 | No.1657 Sum is Prime (Easy Version) |
ユーザー |
|
提出日時 | 2021-08-27 22:02:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,195 ms / 2,000 ms |
コード長 | 1,326 bytes |
コンパイル時間 | 3,636 ms |
コンパイル使用メモリ | 237,996 KB |
実行使用メモリ | 13,788 KB |
最終ジャッジ日時 | 2024-11-21 02:26:20 |
合計ジャッジ時間 | 30,704 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#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; }