結果

問題 No.732 3PrimeCounting
ユーザー 37zigen37zigen
提出日時 2020-04-04 16:19:45
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,204 bytes
コンパイル時間 2,497 ms
コンパイル使用メモリ 77,168 KB
実行使用メモリ 63,652 KB
最終ジャッジ日時 2023-09-16 05:49:22
合計ジャッジ時間 79,302 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 168 ms
62,836 KB
testcase_01 AC 168 ms
58,024 KB
testcase_02 AC 184 ms
58,980 KB
testcase_03 AC 186 ms
58,944 KB
testcase_04 AC 186 ms
58,784 KB
testcase_05 AC 193 ms
58,852 KB
testcase_06 AC 187 ms
58,832 KB
testcase_07 AC 188 ms
58,904 KB
testcase_08 AC 187 ms
56,996 KB
testcase_09 AC 190 ms
59,352 KB
testcase_10 AC 188 ms
59,224 KB
testcase_11 AC 187 ms
58,848 KB
testcase_12 AC 190 ms
59,068 KB
testcase_13 AC 193 ms
59,260 KB
testcase_14 AC 190 ms
59,224 KB
testcase_15 AC 189 ms
57,596 KB
testcase_16 AC 189 ms
58,728 KB
testcase_17 AC 188 ms
58,732 KB
testcase_18 AC 184 ms
59,224 KB
testcase_19 AC 187 ms
59,228 KB
testcase_20 AC 198 ms
58,784 KB
testcase_21 AC 245 ms
59,180 KB
testcase_22 AC 241 ms
59,468 KB
testcase_23 AC 198 ms
58,696 KB
testcase_24 AC 191 ms
58,920 KB
testcase_25 AC 282 ms
58,724 KB
testcase_26 AC 263 ms
59,388 KB
testcase_27 AC 201 ms
59,116 KB
testcase_28 AC 200 ms
58,828 KB
testcase_29 AC 233 ms
58,912 KB
testcase_30 AC 234 ms
58,844 KB
testcase_31 AC 247 ms
59,132 KB
testcase_32 AC 265 ms
59,060 KB
testcase_33 AC 269 ms
58,736 KB
testcase_34 AC 261 ms
59,072 KB
testcase_35 AC 248 ms
58,660 KB
testcase_36 AC 249 ms
59,020 KB
testcase_37 AC 195 ms
58,852 KB
testcase_38 AC 194 ms
59,484 KB
testcase_39 AC 252 ms
59,124 KB
testcase_40 AC 260 ms
58,908 KB
testcase_41 AC 250 ms
59,488 KB
testcase_42 AC 248 ms
58,972 KB
testcase_43 AC 255 ms
60,744 KB
testcase_44 AC 255 ms
59,024 KB
testcase_45 AC 207 ms
56,592 KB
testcase_46 AC 206 ms
59,068 KB
testcase_47 AC 214 ms
58,648 KB
testcase_48 AC 284 ms
57,124 KB
testcase_49 AC 284 ms
58,860 KB
testcase_50 AC 245 ms
58,908 KB
testcase_51 AC 254 ms
58,908 KB
testcase_52 AC 207 ms
59,016 KB
testcase_53 AC 561 ms
59,428 KB
testcase_54 AC 2,181 ms
58,848 KB
testcase_55 AC 2,176 ms
58,936 KB
testcase_56 AC 2,173 ms
58,984 KB
testcase_57 AC 919 ms
59,104 KB
testcase_58 AC 918 ms
59,216 KB
testcase_59 AC 584 ms
59,400 KB
testcase_60 AC 1,132 ms
59,064 KB
testcase_61 AC 1,126 ms
59,224 KB
testcase_62 AC 2,535 ms
58,908 KB
testcase_63 AC 1,587 ms
59,464 KB
testcase_64 AC 1,336 ms
59,480 KB
testcase_65 AC 1,293 ms
58,960 KB
testcase_66 AC 191 ms
58,836 KB
testcase_67 AC 184 ms
59,140 KB
testcase_68 AC 2,342 ms
59,188 KB
testcase_69 AC 2,351 ms
59,120 KB
testcase_70 AC 2,193 ms
58,904 KB
testcase_71 AC 2,193 ms
59,500 KB
testcase_72 AC 1,520 ms
59,244 KB
testcase_73 TLE -
testcase_74 TLE -
testcase_75 AC 271 ms
59,212 KB
testcase_76 AC 2,308 ms
59,172 KB
testcase_77 AC 965 ms
59,368 KB
testcase_78 AC 2,907 ms
59,164 KB
testcase_79 AC 2,376 ms
59,272 KB
testcase_80 AC 2,716 ms
59,384 KB
testcase_81 AC 2,214 ms
59,384 KB
testcase_82 AC 198 ms
58,704 KB
testcase_83 AC 941 ms
59,124 KB
testcase_84 AC 996 ms
59,580 KB
testcase_85 AC 1,997 ms
59,116 KB
testcase_86 AC 2,756 ms
59,460 KB
testcase_87 TLE -
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 p:primes) {
			if(p>N)break;
			for(int target:primes) {
				if(target-p<=0)continue;
				ans+=dp[target-p];
			}
		}
		//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