結果

問題 No.732 3PrimeCounting
ユーザー chocoruskchocorusk
提出日時 2018-09-20 12:25:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 639 ms / 3,000 ms
コード長 1,039 bytes
コンパイル時間 786 ms
コンパイル使用メモリ 82,288 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2024-07-18 08:31:40
合計ジャッジ時間 8,098 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,816 KB
testcase_01 AC 4 ms
6,944 KB
testcase_02 AC 4 ms
6,940 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 4 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 4 ms
6,944 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 4 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 4 ms
6,940 KB
testcase_15 AC 4 ms
6,940 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 4 ms
6,944 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 5 ms
6,940 KB
testcase_22 AC 5 ms
6,940 KB
testcase_23 AC 4 ms
6,940 KB
testcase_24 AC 4 ms
6,940 KB
testcase_25 AC 6 ms
6,944 KB
testcase_26 AC 5 ms
6,944 KB
testcase_27 AC 4 ms
6,940 KB
testcase_28 AC 4 ms
6,940 KB
testcase_29 AC 4 ms
6,940 KB
testcase_30 AC 4 ms
6,940 KB
testcase_31 AC 5 ms
6,944 KB
testcase_32 AC 5 ms
6,944 KB
testcase_33 AC 4 ms
6,940 KB
testcase_34 AC 5 ms
6,944 KB
testcase_35 AC 4 ms
6,944 KB
testcase_36 AC 5 ms
6,940 KB
testcase_37 AC 4 ms
6,944 KB
testcase_38 AC 3 ms
6,940 KB
testcase_39 AC 5 ms
6,940 KB
testcase_40 AC 4 ms
6,940 KB
testcase_41 AC 4 ms
6,940 KB
testcase_42 AC 5 ms
6,940 KB
testcase_43 AC 4 ms
6,944 KB
testcase_44 AC 4 ms
6,940 KB
testcase_45 AC 4 ms
6,944 KB
testcase_46 AC 4 ms
6,940 KB
testcase_47 AC 5 ms
6,940 KB
testcase_48 AC 6 ms
6,944 KB
testcase_49 AC 6 ms
6,944 KB
testcase_50 AC 4 ms
6,944 KB
testcase_51 AC 4 ms
6,940 KB
testcase_52 AC 3 ms
6,940 KB
testcase_53 AC 11 ms
6,940 KB
testcase_54 AC 159 ms
6,944 KB
testcase_55 AC 156 ms
6,940 KB
testcase_56 AC 154 ms
6,944 KB
testcase_57 AC 29 ms
6,944 KB
testcase_58 AC 28 ms
6,944 KB
testcase_59 AC 12 ms
6,944 KB
testcase_60 AC 42 ms
6,940 KB
testcase_61 AC 42 ms
6,940 KB
testcase_62 AC 219 ms
6,944 KB
testcase_63 AC 79 ms
6,940 KB
testcase_64 AC 55 ms
6,944 KB
testcase_65 AC 57 ms
6,940 KB
testcase_66 AC 4 ms
6,944 KB
testcase_67 AC 4 ms
6,944 KB
testcase_68 AC 177 ms
6,944 KB
testcase_69 AC 178 ms
6,944 KB
testcase_70 AC 160 ms
6,940 KB
testcase_71 AC 163 ms
6,940 KB
testcase_72 AC 74 ms
6,940 KB
testcase_73 AC 439 ms
6,940 KB
testcase_74 AC 440 ms
6,940 KB
testcase_75 AC 6 ms
6,940 KB
testcase_76 AC 182 ms
6,944 KB
testcase_77 AC 32 ms
6,940 KB
testcase_78 AC 302 ms
6,944 KB
testcase_79 AC 189 ms
6,940 KB
testcase_80 AC 267 ms
6,940 KB
testcase_81 AC 171 ms
6,944 KB
testcase_82 AC 4 ms
6,940 KB
testcase_83 AC 30 ms
6,944 KB
testcase_84 AC 33 ms
6,940 KB
testcase_85 AC 130 ms
6,940 KB
testcase_86 AC 273 ms
6,944 KB
testcase_87 AC 620 ms
7,040 KB
testcase_88 AC 639 ms
6,948 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; (j<prime.size() && 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