結果

問題 No.843 Triple Primes
ユーザー 👑 kmjpkmjp
提出日時 2019-06-29 00:32:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,192 ms / 2,000 ms
コード長 1,200 bytes
コンパイル時間 1,549 ms
コンパイル使用メモリ 170,648 KB
実行使用メモリ 12,168 KB
最終ジャッジ日時 2023-10-19 17:52:15
合計ジャッジ時間 22,106 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
12,168 KB
testcase_01 AC 1,144 ms
12,168 KB
testcase_02 AC 14 ms
12,168 KB
testcase_03 AC 15 ms
12,168 KB
testcase_04 AC 15 ms
12,168 KB
testcase_05 AC 15 ms
12,168 KB
testcase_06 AC 16 ms
12,168 KB
testcase_07 AC 605 ms
12,168 KB
testcase_08 AC 792 ms
12,168 KB
testcase_09 AC 1,127 ms
12,168 KB
testcase_10 AC 699 ms
12,168 KB
testcase_11 AC 900 ms
12,168 KB
testcase_12 AC 1,120 ms
12,168 KB
testcase_13 AC 982 ms
12,168 KB
testcase_14 AC 970 ms
12,168 KB
testcase_15 AC 635 ms
12,168 KB
testcase_16 AC 675 ms
12,168 KB
testcase_17 AC 15 ms
12,168 KB
testcase_18 AC 14 ms
12,168 KB
testcase_19 AC 14 ms
12,168 KB
testcase_20 AC 76 ms
12,168 KB
testcase_21 AC 35 ms
12,168 KB
testcase_22 AC 256 ms
12,168 KB
testcase_23 AC 274 ms
12,168 KB
testcase_24 AC 83 ms
12,168 KB
testcase_25 AC 56 ms
12,168 KB
testcase_26 AC 1,095 ms
12,168 KB
testcase_27 AC 18 ms
12,168 KB
testcase_28 AC 975 ms
12,168 KB
testcase_29 AC 91 ms
12,168 KB
testcase_30 AC 1,053 ms
12,168 KB
testcase_31 AC 22 ms
12,168 KB
testcase_32 AC 18 ms
12,168 KB
testcase_33 AC 109 ms
12,168 KB
testcase_34 AC 221 ms
12,168 KB
testcase_35 AC 1,192 ms
12,168 KB
testcase_36 AC 49 ms
12,168 KB
testcase_37 AC 526 ms
12,168 KB
testcase_38 AC 345 ms
12,168 KB
testcase_39 AC 1,029 ms
12,168 KB
testcase_40 AC 15 ms
12,168 KB
testcase_41 AC 14 ms
12,168 KB
testcase_42 AC 747 ms
12,168 KB
testcase_43 AC 915 ms
12,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

const int prime_max = 1000000;
vector<int> prime;
int ok[1505050];
int NP,divp[prime_max];

void cprime() {
	if(NP) return;
	for(int i=2;i<prime_max;i++) if(divp[i]==0) {
		if(1LL*i*i<=1000000) ok[1LL*i*i]=1;
		prime.push_back(i); NP++;
		for(ll j=1LL*i*i;j>=i&&j<prime_max;j+=i) if(divp[j]==0) divp[j]=i;
	}
}

int N;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cprime();
	ll ret=0;
	
	cin>>N;
	for(i=0;prime[i]<=N;i++) {
		for(j=i;prime[j]<=N;j++) {
			if(ok[prime[i]+prime[j]]) ret+=1+(i!=j);
		}
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0