結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー V_MelvilleV_Melville
提出日時 2021-08-27 21:51:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 807 bytes
コンパイル時間 2,197 ms
コンパイル使用メモリ 208,484 KB
実行使用メモリ 18,768 KB
最終ジャッジ日時 2024-05-01 02:20:15
合計ジャッジ時間 5,322 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
18,644 KB
testcase_01 AC 59 ms
18,640 KB
testcase_02 AC 196 ms
18,640 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 59 ms
18,640 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 59 ms
18,636 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 59 ms
18,764 KB
testcase_12 AC 188 ms
18,548 KB
testcase_13 AC 111 ms
18,644 KB
testcase_14 AC 122 ms
18,636 KB
testcase_15 AC 143 ms
18,768 KB
testcase_16 AC 80 ms
18,644 KB
testcase_17 AC 64 ms
18,640 KB
testcase_18 AC 69 ms
18,640 KB
testcase_19 AC 194 ms
18,768 KB
testcase_20 AC 95 ms
18,640 KB
testcase_21 AC 219 ms
18,640 KB
testcase_22 AC 61 ms
18,640 KB
testcase_23 AC 76 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;
		int x = 2 * i + 1;
		if (s.count(x)) ++ans;
	}
	
	cout << ans << '\n';
	
	return 0;
}
0