結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー atjh16atjh16
提出日時 2021-09-23 04:06:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 399 bytes
コンパイル時間 1,457 ms
コンパイル使用メモリ 162,784 KB
実行使用メモリ 5,576 KB
最終ジャッジ日時 2023-09-18 19:47:43
合計ジャッジ時間 3,069 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,316 KB
testcase_01 AC 12 ms
5,260 KB
testcase_02 AC 15 ms
5,436 KB
testcase_03 AC 12 ms
5,256 KB
testcase_04 AC 12 ms
5,312 KB
testcase_05 AC 11 ms
5,576 KB
testcase_06 AC 12 ms
5,316 KB
testcase_07 AC 12 ms
5,332 KB
testcase_08 AC 12 ms
5,572 KB
testcase_09 AC 12 ms
5,364 KB
testcase_10 AC 11 ms
5,324 KB
testcase_11 AC 12 ms
5,260 KB
testcase_12 AC 15 ms
5,332 KB
testcase_13 AC 13 ms
5,368 KB
testcase_14 AC 13 ms
5,388 KB
testcase_15 AC 13 ms
5,440 KB
testcase_16 AC 13 ms
5,264 KB
testcase_17 AC 12 ms
5,244 KB
testcase_18 AC 12 ms
5,388 KB
testcase_19 AC 15 ms
5,388 KB
testcase_20 AC 12 ms
5,372 KB
testcase_21 AC 15 ms
5,420 KB
testcase_22 AC 11 ms
5,264 KB
testcase_23 AC 12 ms
5,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int l, r, m = 0;
const long long N = 2e6;
bool f[2000001];

int main()
{
	cin >> l >> r;

	f[1] = 1;

	for (long long i = 2; i <= N; i++) {
		if (!f[i]) {

			for (long long j = i * i; j <= N; j += i) {
				f[j] = 1;
			}
		}
	}

	for (long long i = l; i <= r; i++) {
		if(!f[i])
			m++;

		if (i < r && !f[i * 2 + 1])
			m++;
	}

	cout << m << endl;
}
0