結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー ohreitetsuohreitetsu
提出日時 2021-09-04 15:11:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,317 ms / 2,000 ms
コード長 580 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 69,976 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 23:07:48
合計ジャッジ時間 8,923 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1,188 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 1,096 ms
4,376 KB
testcase_13 AC 393 ms
4,376 KB
testcase_14 AC 554 ms
4,380 KB
testcase_15 AC 720 ms
4,376 KB
testcase_16 AC 162 ms
4,380 KB
testcase_17 AC 31 ms
4,376 KB
testcase_18 AC 81 ms
4,376 KB
testcase_19 AC 1,098 ms
4,376 KB
testcase_20 AC 292 ms
4,380 KB
testcase_21 AC 1,317 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 147 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
typedef long long LL;
int IsPrime(LL n)
{
	int i;
	if (n < 2) {
		return 0;
	}
	else if (n == 2) {
		return 1;
	}
	if (n % 2 == 0) {
		return 0;
	}
	double sqrtNum = sqrt((double)n);
	for (i = 3; i <= sqrtNum; i += 2) {
		if (n % i == 0) {
			return 0;
		}
	}
	return 1;
}
int main()
{
	LL L, R,A;
	cin >> L >> R;
	int Count = 0;
	for (A = L; A <= R; A++) {
		if (IsPrime(A)) {
			Count++;
		}
	}
	for (A = L; A < R; A++) {
		if (IsPrime(A+A+1)) {
			Count++;
		}
	}
	cout << Count << endl;
	return 0;
}
0