結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー atjh16atjh16
提出日時 2021-09-12 16:43:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 718 ms / 2,000 ms
コード長 646 bytes
コンパイル時間 1,789 ms
コンパイル使用メモリ 168,796 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 13:11:31
合計ジャッジ時間 6,752 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 604 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 9 ms
4,376 KB
testcase_12 AC 551 ms
4,376 KB
testcase_13 AC 252 ms
4,376 KB
testcase_14 AC 274 ms
4,376 KB
testcase_15 AC 367 ms
4,380 KB
testcase_16 AC 110 ms
4,380 KB
testcase_17 AC 19 ms
4,376 KB
testcase_18 AC 47 ms
4,380 KB
testcase_19 AC 673 ms
4,376 KB
testcase_20 AC 155 ms
4,380 KB
testcase_21 AC 718 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 57 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int l, r, m = 0;
bool f[1501];
vector<long long> p = { 2 };

bool isprime(int t) {
	if (t == 1)
		return 0;

	for (long long k : p) {
		if (t == k)
			return 1;

		if (t % k == 0) {
			return 0;
		}
	}

	return 1;
}

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

	for (long long i = 3; i <= 1500; i += 2) {
		if (!f[i]) {
			p.push_back(i);

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

	for (long long i = l; i < r; i++) {
		long long a[2] = { i, i * 2 + 1 };
		
		for(int j = 0; j < 2; j++){
			if (isprime(a[j]))
				m++;
		}
	}

	if (isprime(r))
		m++;

	cout << m << endl;
}
0