結果

問題 No.732 3PrimeCounting
ユーザー chocoruskchocorusk
提出日時 2018-09-20 12:25:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 678 ms / 3,000 ms
コード長 1,039 bytes
コンパイル時間 731 ms
コンパイル使用メモリ 76,476 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2023-09-25 10:30:01
合計ジャッジ時間 9,613 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,452 KB
testcase_01 AC 4 ms
6,412 KB
testcase_02 AC 3 ms
6,492 KB
testcase_03 AC 3 ms
6,404 KB
testcase_04 AC 3 ms
6,496 KB
testcase_05 AC 4 ms
6,564 KB
testcase_06 AC 3 ms
6,476 KB
testcase_07 AC 3 ms
6,476 KB
testcase_08 AC 3 ms
6,488 KB
testcase_09 AC 3 ms
6,400 KB
testcase_10 AC 3 ms
6,404 KB
testcase_11 AC 4 ms
6,476 KB
testcase_12 AC 3 ms
6,440 KB
testcase_13 AC 3 ms
6,396 KB
testcase_14 AC 4 ms
6,416 KB
testcase_15 AC 3 ms
6,400 KB
testcase_16 AC 3 ms
6,440 KB
testcase_17 AC 3 ms
6,536 KB
testcase_18 AC 4 ms
6,472 KB
testcase_19 AC 4 ms
6,532 KB
testcase_20 AC 3 ms
6,460 KB
testcase_21 AC 3 ms
6,432 KB
testcase_22 AC 3 ms
6,488 KB
testcase_23 AC 3 ms
6,432 KB
testcase_24 AC 3 ms
6,420 KB
testcase_25 AC 5 ms
6,556 KB
testcase_26 AC 5 ms
6,516 KB
testcase_27 AC 3 ms
6,496 KB
testcase_28 AC 4 ms
6,528 KB
testcase_29 AC 4 ms
6,716 KB
testcase_30 AC 3 ms
6,428 KB
testcase_31 AC 4 ms
6,492 KB
testcase_32 AC 4 ms
6,568 KB
testcase_33 AC 5 ms
6,448 KB
testcase_34 AC 6 ms
6,472 KB
testcase_35 AC 4 ms
6,468 KB
testcase_36 AC 5 ms
6,460 KB
testcase_37 AC 3 ms
6,468 KB
testcase_38 AC 3 ms
6,596 KB
testcase_39 AC 5 ms
6,584 KB
testcase_40 AC 5 ms
6,436 KB
testcase_41 AC 4 ms
6,416 KB
testcase_42 AC 5 ms
6,464 KB
testcase_43 AC 3 ms
6,716 KB
testcase_44 AC 5 ms
6,572 KB
testcase_45 AC 4 ms
6,436 KB
testcase_46 AC 3 ms
6,420 KB
testcase_47 AC 3 ms
6,540 KB
testcase_48 AC 5 ms
6,572 KB
testcase_49 AC 6 ms
6,552 KB
testcase_50 AC 4 ms
6,504 KB
testcase_51 AC 4 ms
6,488 KB
testcase_52 AC 3 ms
6,564 KB
testcase_53 AC 11 ms
6,472 KB
testcase_54 AC 164 ms
6,716 KB
testcase_55 AC 176 ms
6,760 KB
testcase_56 AC 166 ms
6,764 KB
testcase_57 AC 31 ms
6,588 KB
testcase_58 AC 32 ms
6,536 KB
testcase_59 AC 12 ms
6,488 KB
testcase_60 AC 47 ms
6,612 KB
testcase_61 AC 47 ms
6,536 KB
testcase_62 AC 257 ms
6,944 KB
testcase_63 AC 91 ms
6,748 KB
testcase_64 AC 62 ms
6,780 KB
testcase_65 AC 61 ms
6,628 KB
testcase_66 AC 3 ms
6,408 KB
testcase_67 AC 3 ms
6,500 KB
testcase_68 AC 209 ms
6,724 KB
testcase_69 AC 189 ms
6,740 KB
testcase_70 AC 169 ms
6,844 KB
testcase_71 AC 172 ms
6,700 KB
testcase_72 AC 85 ms
6,652 KB
testcase_73 AC 470 ms
6,900 KB
testcase_74 AC 477 ms
6,784 KB
testcase_75 AC 5 ms
6,624 KB
testcase_76 AC 184 ms
6,756 KB
testcase_77 AC 36 ms
6,552 KB
testcase_78 AC 344 ms
6,740 KB
testcase_79 AC 206 ms
6,772 KB
testcase_80 AC 276 ms
6,852 KB
testcase_81 AC 172 ms
6,912 KB
testcase_82 AC 4 ms
6,536 KB
testcase_83 AC 34 ms
6,808 KB
testcase_84 AC 38 ms
6,528 KB
testcase_85 AC 143 ms
6,664 KB
testcase_86 AC 290 ms
6,916 KB
testcase_87 AC 674 ms
6,848 KB
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; (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