結果
問題 | No.1657 Sum is Prime (Easy Version) |
ユーザー | Hideaki Ito |
提出日時 | 2021-08-27 21:37:06 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 50 ms / 2,000 ms |
コード長 | 1,340 bytes |
コンパイル時間 | 1,484 ms |
コンパイル使用メモリ | 167,704 KB |
実行使用メモリ | 7,340 KB |
最終ジャッジ日時 | 2023-08-13 08:14:31 |
合計ジャッジ時間 | 3,189 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 20 ms
7,104 KB |
testcase_01 | AC | 19 ms
7,152 KB |
testcase_02 | AC | 44 ms
7,076 KB |
testcase_03 | AC | 19 ms
7,096 KB |
testcase_04 | AC | 20 ms
7,136 KB |
testcase_05 | AC | 20 ms
7,088 KB |
testcase_06 | AC | 19 ms
7,156 KB |
testcase_07 | AC | 20 ms
7,024 KB |
testcase_08 | AC | 20 ms
7,048 KB |
testcase_09 | AC | 19 ms
7,144 KB |
testcase_10 | AC | 19 ms
7,088 KB |
testcase_11 | AC | 20 ms
7,028 KB |
testcase_12 | AC | 42 ms
7,256 KB |
testcase_13 | AC | 29 ms
7,028 KB |
testcase_14 | AC | 30 ms
7,080 KB |
testcase_15 | AC | 34 ms
7,152 KB |
testcase_16 | AC | 24 ms
7,140 KB |
testcase_17 | AC | 21 ms
7,340 KB |
testcase_18 | AC | 22 ms
7,032 KB |
testcase_19 | AC | 46 ms
7,152 KB |
testcase_20 | AC | 25 ms
7,108 KB |
testcase_21 | AC | 50 ms
7,172 KB |
testcase_22 | AC | 20 ms
7,100 KB |
testcase_23 | AC | 23 ms
7,048 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--) #define rrep(i,n) RREP(i,(n)-1,0) #define all(v) v.begin(), v.end() #define endk '\n' const int inf = 1e9+7; const ll longinf = 1LL<<60; const ll mod = 1e9+7; const ll mod2 = 998244353; const ld eps = 1e-10; template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;} template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;} bool arr[2000005]; vector<ll> primes; void Eratosthenes(int N) { for(int i=0; i<=N; i++) { arr[i] = true; } for(int i=2; i<=N; i++) { if(arr[i]) { for(int j=0; i*(j+2)<=N; j++) { arr[i*(j+2)] = false; } } } for(int i=2; i<=N; i++) { if(arr[i]) { primes.push_back(i); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); int l, r; cin >> l >> r; Eratosthenes(2000005); int ans = 0; ans += upper_bound(all(primes), r) - lower_bound(all(primes), l); for(int a=l; a<r; a++) { int b = a+1; int sum = a+b; auto itr = lower_bound(all(primes), sum); if(itr == primes.end()) continue; if(*itr == sum) ans++; } cout << ans << endk; return 0; }