結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー V_MelvilleV_Melville
提出日時 2021-08-27 22:03:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 830 bytes
コンパイル時間 1,828 ms
コンパイル使用メモリ 209,996 KB
実行使用メモリ 18,768 KB
最終ジャッジ日時 2024-05-01 02:37:22
合計ジャッジ時間 4,558 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
18,640 KB
testcase_01 AC 48 ms
18,640 KB
testcase_02 AC 171 ms
18,764 KB
testcase_03 AC 49 ms
18,640 KB
testcase_04 AC 52 ms
18,640 KB
testcase_05 AC 49 ms
18,640 KB
testcase_06 AC 49 ms
18,636 KB
testcase_07 AC 49 ms
18,644 KB
testcase_08 AC 52 ms
18,640 KB
testcase_09 AC 52 ms
18,640 KB
testcase_10 AC 50 ms
18,640 KB
testcase_11 AC 54 ms
18,764 KB
testcase_12 AC 178 ms
18,644 KB
testcase_13 AC 98 ms
18,636 KB
testcase_14 AC 105 ms
18,644 KB
testcase_15 AC 136 ms
18,768 KB
testcase_16 AC 71 ms
18,640 KB
testcase_17 AC 54 ms
18,768 KB
testcase_18 AC 59 ms
18,640 KB
testcase_19 AC 172 ms
18,644 KB
testcase_20 AC 81 ms
18,640 KB
testcase_21 AC 198 ms
18,584 KB
testcase_22 AC 50 ms
18,640 KB
testcase_23 AC 64 ms
18,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::set;
using std::vector;
using ll = long long;

// linear sieve
vector<int> ps, pf;
void sieve(int mx) {
    pf.resize(mx + 1);
    rep(i, mx + 1) pf[i] = i;
    for (int i = 2; i <= mx; ++i) {
        if (pf[i] == i) ps.push_back(i);
        for (int j = 0; j < ps.size() and ps[j] <= pf[i]; ++j) {
            int x = ps[j] * i;
            if (x > mx) break;
            pf[x] = ps[j];
        }
    }
}

int main() {
	const int MX = 2000005;
	sieve(MX);
	set<int> s;
	for (int p : ps) s.insert(p);
	
	int l, r;
	cin >> l >> r;
	
	ll ans = 0;
	for (int i = l; i <= r; ++i) {
		if (s.count(i)) ++ans;
		if (i == r) continue;
		ll x = 2 * i + 1;
		if (s.count(x)) ++ans;
	}
	
	cout << ans << '\n';
	
	return 0;
}
0