結果

問題 No.732 3PrimeCounting
ユーザー ohreitetsuohreitetsu
提出日時 2018-09-07 23:01:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 962 bytes
コンパイル時間 737 ms
コンパイル使用メモリ 85,856 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-19 22:14:46
合計ジャッジ時間 26,269 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
4,596 KB
testcase_01 AC 28 ms
4,544 KB
testcase_02 AC 28 ms
4,600 KB
testcase_03 AC 28 ms
4,736 KB
testcase_04 AC 28 ms
4,712 KB
testcase_05 AC 28 ms
4,560 KB
testcase_06 AC 28 ms
4,596 KB
testcase_07 AC 28 ms
4,588 KB
testcase_08 AC 27 ms
4,548 KB
testcase_09 AC 27 ms
4,592 KB
testcase_10 AC 28 ms
4,524 KB
testcase_11 AC 27 ms
4,524 KB
testcase_12 AC 28 ms
4,540 KB
testcase_13 AC 27 ms
4,560 KB
testcase_14 AC 27 ms
4,568 KB
testcase_15 AC 28 ms
4,576 KB
testcase_16 AC 27 ms
4,608 KB
testcase_17 AC 27 ms
4,560 KB
testcase_18 AC 28 ms
4,712 KB
testcase_19 AC 28 ms
4,520 KB
testcase_20 AC 36 ms
4,520 KB
testcase_21 AC 376 ms
4,604 KB
testcase_22 AC 376 ms
4,600 KB
testcase_23 AC 28 ms
4,548 KB
testcase_24 AC 28 ms
4,548 KB
testcase_25 AC 2,054 ms
4,556 KB
testcase_26 AC 841 ms
4,604 KB
testcase_27 AC 52 ms
4,560 KB
testcase_28 AC 53 ms
4,716 KB
testcase_29 AC 217 ms
4,848 KB
testcase_30 AC 214 ms
4,584 KB
testcase_31 AC 466 ms
4,564 KB
testcase_32 AC 1,164 ms
4,556 KB
testcase_33 AC 1,190 ms
4,584 KB
testcase_34 AC 1,196 ms
4,568 KB
testcase_35 AC 608 ms
4,548 KB
testcase_36 AC 608 ms
4,552 KB
testcase_37 AC 31 ms
4,628 KB
testcase_38 AC 31 ms
4,536 KB
testcase_39 AC 681 ms
4,600 KB
testcase_40 AC 517 ms
4,712 KB
testcase_41 AC 519 ms
4,856 KB
testcase_42 AC 519 ms
4,696 KB
testcase_43 AC 284 ms
4,668 KB
testcase_44 AC 286 ms
4,628 KB
testcase_45 AC 72 ms
4,540 KB
testcase_46 AC 72 ms
4,580 KB
testcase_47 AC 119 ms
4,604 KB
testcase_48 AC 2,482 ms
4,600 KB
testcase_49 AC 2,483 ms
4,532 KB
testcase_50 AC 390 ms
4,628 KB
testcase_51 AC 406 ms
4,584 KB
testcase_52 AC 63 ms
4,612 KB
testcase_53 TLE -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <math.h>
#include <vector>
#include <map>
using namespace std;
typedef long long LL;
int IsPrime (int 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(int argc, char* argv[])
{
	int N;
	cin>>N;
	int i,j,k;
	LL ans=0;
	map<int,int> myMap;
	map<int,int>::iterator mit;
	for (i=3;i<=300000;i+=2){
		if (IsPrime(i)){
			myMap[i]=1;
		}
	}
	vector<int> Prime;
	for (i=3;i<=N;i+=2){
		mit=myMap.find(i);
		if (mit!=myMap.end()){
			Prime.push_back(i);
		}
	}

	int PrimeNum=Prime.size();
	for (i=0;i<PrimeNum-2;i++){
		for (j=i+1;j<PrimeNum-1;j++){
			for (k=j+1;k<PrimeNum;k++){
				mit=myMap.find(Prime[i]+Prime[j]+Prime[k]);
				if (mit!=myMap.end()){
					ans++;
				}
			}
		}
	}

	cout<<ans<<endl;
	return 0;
}
0