結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー ohreitetsu
提出日時 2021-09-04 15:11:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,210 ms / 2,000 ms
コード長 580 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 71,536 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-18 01:51:49
合計ジャッジ時間 7,898 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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