結果

問題 No.843 Triple Primes
ユーザー ohreitetsuohreitetsu
提出日時 2019-06-29 13:49:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 834 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 78,768 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 23:12:41
合計ジャッジ時間 5,276 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 143 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 107 ms
4,380 KB
testcase_08 AC 120 ms
4,380 KB
testcase_09 AC 142 ms
4,376 KB
testcase_10 AC 112 ms
4,380 KB
testcase_11 AC 127 ms
4,376 KB
testcase_12 AC 138 ms
4,376 KB
testcase_13 AC 133 ms
4,376 KB
testcase_14 AC 134 ms
4,380 KB
testcase_15 AC 109 ms
4,376 KB
testcase_16 AC 110 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 25 ms
4,376 KB
testcase_21 AC 11 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 26 ms
4,380 KB
testcase_25 AC 18 ms
4,380 KB
testcase_26 AC 142 ms
4,376 KB
testcase_27 WA -
testcase_28 AC 135 ms
4,376 KB
testcase_29 AC 30 ms
4,376 KB
testcase_30 AC 139 ms
4,376 KB
testcase_31 WA -
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 33 ms
4,376 KB
testcase_34 AC 57 ms
4,380 KB
testcase_35 AC 142 ms
4,380 KB
testcase_36 AC 17 ms
4,380 KB
testcase_37 AC 101 ms
4,380 KB
testcase_38 AC 79 ms
4,376 KB
testcase_39 AC 136 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 116 ms
4,380 KB
testcase_43 AC 127 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <math.h>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;
int IsPrime (LL n)
{
    int i;
	if (n < 2){
        return 0;
	}
	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(int argc, char* argv[])
{
	LL N,i,j;
	cin>>N;
	vector<LL> pri2;
	vector<LL> pri;
	LL I,J;
	I=0;
	for (i=1;i<=N;i++){
		if (IsPrime(i)==1){
			pri.push_back(i);
			if (I<=N){
				I=i*i;
				pri2.push_back(i*i);
			}
		}
	}
	int ans=0;
	int n1=pri.size();
	int n2=pri2.size();
	for (i=0;i<n2;i++){
		I=pri2[i];
		j=0;
		while (j<n1 &&pri[j]<=I){
			J=I-pri[j];
			if (IsPrime(J)==1){
				ans++;
			}
			j++;
		}
	}
	cout<<ans<<endl;
	return 0;
}
0