結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー atjh16atjh16
提出日時 2021-09-12 16:21:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 618 bytes
コンパイル時間 2,542 ms
コンパイル使用メモリ 168,244 KB
実行使用メモリ 7,164 KB
最終ジャッジ日時 2023-09-06 11:52:33
合計ジャッジ時間 7,832 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 550 ms
6,956 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 3 ms
4,384 KB
testcase_12 AC 500 ms
6,992 KB
testcase_13 AC 195 ms
5,140 KB
testcase_14 AC 254 ms
5,668 KB
testcase_15 AC 330 ms
5,764 KB
testcase_16 AC 84 ms
4,452 KB
testcase_17 AC 20 ms
4,864 KB
testcase_18 AC 43 ms
5,060 KB
testcase_19 AC 526 ms
6,836 KB
testcase_20 AC 141 ms
5,384 KB
testcase_21 AC 621 ms
7,164 KB
testcase_22 AC 10 ms
7,012 KB
testcase_23 AC 72 ms
7,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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

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

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

	for (long long i = l; i <= r; i++) {
		for (long long j = i; j <= i + 2; j++) {
			long long n = (i + j) * (j - i + 1) / 2;
			bool f = 0;

			for (long long k : p) {
				if (n % k == 0) {
					f = 1;
					break;
				}

				if (k > sqrt(n))
					break;
			}

			if (!f)
				m++;
		}
	}

	cout << m << endl;
}
0