結果

問題 No.732 3PrimeCounting
ユーザー 37zigen37zigen
提出日時 2020-04-04 16:25:14
言語 Java19
(openjdk 21)
結果
AC  
実行時間 2,948 ms / 3,000 ms
コード長 1,416 bytes
コンパイル時間 2,382 ms
コンパイル使用メモリ 76,500 KB
実行使用メモリ 61,436 KB
最終ジャッジ日時 2023-09-16 05:51:40
合計ジャッジ時間 62,996 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 162 ms
58,120 KB
testcase_01 AC 165 ms
57,892 KB
testcase_02 AC 179 ms
58,984 KB
testcase_03 AC 184 ms
58,744 KB
testcase_04 AC 176 ms
58,764 KB
testcase_05 AC 180 ms
58,776 KB
testcase_06 AC 181 ms
59,228 KB
testcase_07 AC 178 ms
59,240 KB
testcase_08 AC 178 ms
58,732 KB
testcase_09 AC 184 ms
58,740 KB
testcase_10 AC 179 ms
58,840 KB
testcase_11 AC 178 ms
58,844 KB
testcase_12 AC 180 ms
58,908 KB
testcase_13 AC 180 ms
59,240 KB
testcase_14 AC 185 ms
59,028 KB
testcase_15 AC 179 ms
59,176 KB
testcase_16 AC 180 ms
58,852 KB
testcase_17 AC 179 ms
59,268 KB
testcase_18 AC 186 ms
61,140 KB
testcase_19 AC 180 ms
59,040 KB
testcase_20 AC 202 ms
58,972 KB
testcase_21 AC 245 ms
58,796 KB
testcase_22 AC 247 ms
59,024 KB
testcase_23 AC 194 ms
58,888 KB
testcase_24 AC 192 ms
58,888 KB
testcase_25 AC 277 ms
58,840 KB
testcase_26 AC 260 ms
58,816 KB
testcase_27 AC 220 ms
59,184 KB
testcase_28 AC 208 ms
58,724 KB
testcase_29 AC 232 ms
58,724 KB
testcase_30 AC 233 ms
58,544 KB
testcase_31 AC 247 ms
58,944 KB
testcase_32 AC 264 ms
58,872 KB
testcase_33 AC 264 ms
59,168 KB
testcase_34 AC 267 ms
58,668 KB
testcase_35 AC 254 ms
58,876 KB
testcase_36 AC 248 ms
58,840 KB
testcase_37 AC 198 ms
58,880 KB
testcase_38 AC 197 ms
58,896 KB
testcase_39 AC 253 ms
57,312 KB
testcase_40 AC 248 ms
58,976 KB
testcase_41 AC 256 ms
58,840 KB
testcase_42 AC 249 ms
59,080 KB
testcase_43 AC 253 ms
59,440 KB
testcase_44 AC 252 ms
58,700 KB
testcase_45 AC 211 ms
60,716 KB
testcase_46 AC 210 ms
58,784 KB
testcase_47 AC 216 ms
58,904 KB
testcase_48 AC 283 ms
59,060 KB
testcase_49 AC 279 ms
59,012 KB
testcase_50 AC 248 ms
58,884 KB
testcase_51 AC 241 ms
58,924 KB
testcase_52 AC 210 ms
59,060 KB
testcase_53 AC 426 ms
59,964 KB
testcase_54 AC 1,530 ms
59,464 KB
testcase_55 AC 1,531 ms
57,576 KB
testcase_56 AC 1,522 ms
59,688 KB
testcase_57 AC 656 ms
59,696 KB
testcase_58 AC 659 ms
59,476 KB
testcase_59 AC 442 ms
59,644 KB
testcase_60 AC 794 ms
59,632 KB
testcase_61 AC 788 ms
59,288 KB
testcase_62 AC 1,796 ms
59,456 KB
testcase_63 AC 1,098 ms
59,320 KB
testcase_64 AC 909 ms
59,584 KB
testcase_65 AC 907 ms
59,268 KB
testcase_66 AC 180 ms
58,912 KB
testcase_67 AC 191 ms
58,712 KB
testcase_68 AC 1,642 ms
59,460 KB
testcase_69 AC 1,650 ms
59,692 KB
testcase_70 AC 1,536 ms
59,600 KB
testcase_71 AC 1,532 ms
61,268 KB
testcase_72 AC 1,060 ms
59,400 KB
testcase_73 AC 2,411 ms
59,288 KB
testcase_74 AC 2,424 ms
59,668 KB
testcase_75 AC 289 ms
59,052 KB
testcase_76 AC 1,626 ms
59,668 KB
testcase_77 AC 683 ms
59,448 KB
testcase_78 AC 2,056 ms
59,508 KB
testcase_79 AC 1,673 ms
59,692 KB
testcase_80 AC 1,912 ms
59,596 KB
testcase_81 AC 1,575 ms
59,464 KB
testcase_82 AC 209 ms
58,968 KB
testcase_83 AC 667 ms
59,688 KB
testcase_84 AC 716 ms
61,436 KB
testcase_85 AC 1,393 ms
59,280 KB
testcase_86 AC 1,947 ms
59,560 KB
testcase_87 AC 2,948 ms
59,832 KB
testcase_88 AC 2,942 ms
59,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {

	public static void main(String[] args) {
		long curtime=System.currentTimeMillis();
		new Main().run();
		System.err.println(System.currentTimeMillis()-curtime);
	}
	
	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;
		int src=0;
		for(int p:primes) {
			if(p>N)break;
			while(src<primes.size()&&primes.get(src)-p<=0)++src;
			for(int i=src;i<primes.size();++i) {
				int target=primes.get(i);
				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