結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
18,640 KB
testcase_01 AC 51 ms
18,768 KB
testcase_02 AC 171 ms
18,656 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 49 ms
18,576 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 54 ms
18,636 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 51 ms
18,640 KB
testcase_12 AC 163 ms
18,636 KB
testcase_13 AC 98 ms
18,640 KB
testcase_14 AC 104 ms
18,636 KB
testcase_15 AC 123 ms
18,640 KB
testcase_16 AC 72 ms
18,772 KB
testcase_17 AC 56 ms
18,644 KB
testcase_18 AC 67 ms
18,768 KB
testcase_19 AC 189 ms
18,640 KB
testcase_20 AC 84 ms
18,644 KB
testcase_21 AC 196 ms
18,772 KB
testcase_22 AC 53 ms
18,768 KB
testcase_23 AC 66 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;
		ll x = 2 * i + 1;
		if (s.count(x)) ++ans;
	}
	
	cout << ans << '\n';
	
	return 0;
}
0