結果

問題 No.732 3PrimeCounting
ユーザー chocoruskchocorusk
提出日時 2018-09-20 12:23:55
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,019 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 75,672 KB
実行使用メモリ 7,052 KB
最終ジャッジ日時 2023-09-25 10:29:40
合計ジャッジ時間 13,393 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,480 KB
testcase_01 AC 3 ms
6,632 KB
testcase_02 AC 3 ms
6,528 KB
testcase_03 AC 3 ms
6,556 KB
testcase_04 AC 3 ms
6,448 KB
testcase_05 AC 4 ms
6,448 KB
testcase_06 AC 3 ms
6,484 KB
testcase_07 AC 3 ms
6,444 KB
testcase_08 AC 3 ms
6,732 KB
testcase_09 AC 3 ms
6,552 KB
testcase_10 AC 3 ms
6,476 KB
testcase_11 AC 3 ms
6,488 KB
testcase_12 AC 4 ms
6,456 KB
testcase_13 AC 4 ms
6,448 KB
testcase_14 AC 4 ms
6,484 KB
testcase_15 AC 3 ms
6,480 KB
testcase_16 AC 4 ms
6,484 KB
testcase_17 AC 3 ms
6,764 KB
testcase_18 AC 4 ms
6,484 KB
testcase_19 AC 4 ms
6,476 KB
testcase_20 AC 3 ms
6,480 KB
testcase_21 AC 4 ms
6,564 KB
testcase_22 AC 5 ms
6,564 KB
testcase_23 AC 4 ms
6,464 KB
testcase_24 AC 4 ms
6,472 KB
testcase_25 AC 5 ms
6,512 KB
testcase_26 AC 4 ms
6,496 KB
testcase_27 AC 3 ms
6,480 KB
testcase_28 AC 3 ms
6,480 KB
testcase_29 AC 4 ms
6,484 KB
testcase_30 AC 3 ms
6,544 KB
testcase_31 AC 3 ms
6,640 KB
testcase_32 AC 4 ms
6,500 KB
testcase_33 AC 4 ms
6,752 KB
testcase_34 AC 5 ms
6,652 KB
testcase_35 AC 4 ms
6,512 KB
testcase_36 AC 4 ms
6,584 KB
testcase_37 AC 4 ms
6,568 KB
testcase_38 AC 3 ms
6,460 KB
testcase_39 AC 5 ms
6,508 KB
testcase_40 AC 4 ms
6,648 KB
testcase_41 AC 4 ms
6,548 KB
testcase_42 AC 4 ms
6,504 KB
testcase_43 AC 4 ms
6,460 KB
testcase_44 AC 3 ms
6,464 KB
testcase_45 AC 3 ms
6,460 KB
testcase_46 AC 3 ms
6,560 KB
testcase_47 AC 4 ms
6,488 KB
testcase_48 AC 6 ms
6,516 KB
testcase_49 AC 6 ms
6,516 KB
testcase_50 AC 5 ms
6,464 KB
testcase_51 AC 3 ms
6,488 KB
testcase_52 AC 3 ms
6,456 KB
testcase_53 AC 11 ms
6,540 KB
testcase_54 AC 179 ms
6,732 KB
testcase_55 RE -
testcase_56 RE -
testcase_57 AC 32 ms
6,592 KB
testcase_58 AC 31 ms
6,592 KB
testcase_59 RE -
testcase_60 AC 49 ms
6,684 KB
testcase_61 AC 47 ms
6,684 KB
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 AC 4 ms
6,480 KB
testcase_67 AC 3 ms
6,500 KB
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
testcase_73 RE -
testcase_74 RE -
testcase_75 AC 5 ms
6,556 KB
testcase_76 RE -
testcase_77 AC 34 ms
6,604 KB
testcase_78 RE -
testcase_79 RE -
testcase_80 RE -
testcase_81 AC 170 ms
6,732 KB
testcase_82 AC 3 ms
6,536 KB
testcase_83 AC 33 ms
6,856 KB
testcase_84 AC 38 ms
6,748 KB
testcase_85 RE -
testcase_86 RE -
testcase_87 RE -
testcase_88 AC 678 ms
6,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int n;
vector<int> prime;
bool isprime[300001];
 
void sieve(){
	for(int i=3; i<=3*n; i+=2){
		isprime[i]=1;
	}
	isprime[2]=1;
	prime.push_back(2);
	for(int i=3; i<=3*n; i++){
		if(isprime[i]){
			prime.push_back(i);
			for(int j=2*i; j<=3*n; j+=i){
				isprime[j]=0;
			}
		}
	}
	return;
}

int main()
{
	cin>>n;
	sieve();
	ll ct1[200001]={}, ct2[200001]={}, ct3=0;
	for(int i=0; prime[i]<=n; i++){
		for(int j=0; prime[j]<=n; j++){
			ct1[prime[i]+prime[j]]++;
			if(isprime[2*prime[i]+prime[j]]) ct3+=3;
		}
	}
	for(int i=0; prime[i]<=n; i++){
		for(int j=i+1; prime[j]-prime[i]<=2*n; j++){
			ct2[prime[j]-prime[i]]++;
		}
	}
	ll ans=0;
	for(int i=1; i<=2*n; i++){
		ans+=ct1[i]*ct2[i];
	}
	cout<<(ans-ct3)/6<<endl;
	return 0;
}
0