結果

問題 No.732 3PrimeCounting
ユーザー 37zigen37zigen
提出日時 2020-04-04 16:06:05
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,233 bytes
コンパイル時間 2,548 ms
コンパイル使用メモリ 76,776 KB
実行使用メモリ 67,564 KB
最終ジャッジ日時 2023-09-16 05:44:59
合計ジャッジ時間 21,240 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 161 ms
57,908 KB
testcase_01 AC 164 ms
57,868 KB
testcase_02 AC 165 ms
57,828 KB
testcase_03 AC 167 ms
58,080 KB
testcase_04 AC 165 ms
58,080 KB
testcase_05 AC 163 ms
57,812 KB
testcase_06 AC 164 ms
57,912 KB
testcase_07 AC 160 ms
58,164 KB
testcase_08 AC 161 ms
57,696 KB
testcase_09 AC 163 ms
57,844 KB
testcase_10 AC 164 ms
57,836 KB
testcase_11 AC 164 ms
57,860 KB
testcase_12 AC 161 ms
58,164 KB
testcase_13 AC 163 ms
58,044 KB
testcase_14 AC 162 ms
57,796 KB
testcase_15 AC 162 ms
57,696 KB
testcase_16 AC 164 ms
58,024 KB
testcase_17 AC 163 ms
57,804 KB
testcase_18 AC 170 ms
57,896 KB
testcase_19 AC 166 ms
57,692 KB
testcase_20 AC 182 ms
58,452 KB
testcase_21 AC 215 ms
58,268 KB
testcase_22 AC 205 ms
58,144 KB
testcase_23 AC 165 ms
57,864 KB
testcase_24 AC 168 ms
57,856 KB
testcase_25 AC 232 ms
57,964 KB
testcase_26 AC 213 ms
58,312 KB
testcase_27 AC 174 ms
57,880 KB
testcase_28 AC 183 ms
57,688 KB
testcase_29 AC 189 ms
58,072 KB
testcase_30 AC 192 ms
57,796 KB
testcase_31 AC 215 ms
58,160 KB
testcase_32 AC 226 ms
58,124 KB
testcase_33 AC 218 ms
58,272 KB
testcase_34 AC 221 ms
58,264 KB
testcase_35 AC 209 ms
58,140 KB
testcase_36 AC 209 ms
58,152 KB
testcase_37 AC 170 ms
58,132 KB
testcase_38 AC 171 ms
57,984 KB
testcase_39 AC 216 ms
58,504 KB
testcase_40 AC 208 ms
58,168 KB
testcase_41 AC 213 ms
58,400 KB
testcase_42 AC 205 ms
58,268 KB
testcase_43 AC 206 ms
58,588 KB
testcase_44 AC 211 ms
58,052 KB
testcase_45 AC 177 ms
58,104 KB
testcase_46 AC 180 ms
57,780 KB
testcase_47 AC 186 ms
58,176 KB
testcase_48 AC 231 ms
58,244 KB
testcase_49 AC 236 ms
58,512 KB
testcase_50 AC 208 ms
58,512 KB
testcase_51 AC 208 ms
57,960 KB
testcase_52 AC 183 ms
57,692 KB
testcase_53 AC 385 ms
59,092 KB
testcase_54 TLE -
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 #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}
	
	int MAX=300001;
	boolean[] isPrime=new boolean[MAX];
	ArrayList<Integer> primes=new ArrayList<>();
	{
		Arrays.fill(isPrime, true);
		isPrime[0]=isPrime[1]=false;
		for(int i=2;i<isPrime.length;++i) {
			if(!isPrime[i])continue;
			primes.add(i);
			for(int j=2*i;j<isPrime.length;j+=i)
				isPrime[j]=false;
		}
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();//5<=N<=1e5
		long[] dp=new long[MAX];
		for(int p:primes) {
			if(p>N)break;
			for(int q:primes) {
				if(q>N)break;
				++dp[p+q];
			}
		}
		long ans=0;
		for(int i=0;i<MAX;++i) {
			if(dp[i]==0)continue;
			for(int p:primes) {
				if(p>N)break;
				if(i%2==1&&p>2)break;
				if(isPrime[i+p])ans+=dp[i];
			}
		}
		//a+b+c が 素数 かつ a==b==c は存在しない。
		for(int p:primes) {
			if(p>N)break;
			for(int q:primes) {
				if(q>N)break;
				if(isPrime[p+p+q]) {
					ans-=3;
				}
			}
		}
		if(ans%6!=0)throw new AssertionError();
		System.out.println(ans/6);
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}

0