結果

問題 No.458 異なる素数の和
ユーザー TententenTententen
提出日時 2020-12-14 14:26:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 685 bytes
コンパイル時間 2,232 ms
コンパイル使用メモリ 74,100 KB
実行使用メモリ 57,684 KB
最終ジャッジ日時 2023-10-20 05:00:05
合計ジャッジ時間 7,621 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
57,444 KB
testcase_01 AC 158 ms
57,444 KB
testcase_02 AC 154 ms
57,480 KB
testcase_03 AC 142 ms
57,520 KB
testcase_04 AC 141 ms
57,492 KB
testcase_05 AC 170 ms
57,380 KB
testcase_06 AC 154 ms
57,432 KB
testcase_07 AC 132 ms
57,404 KB
testcase_08 AC 170 ms
57,228 KB
testcase_09 AC 141 ms
57,448 KB
testcase_10 AC 135 ms
57,496 KB
testcase_11 AC 178 ms
57,476 KB
testcase_12 AC 133 ms
57,416 KB
testcase_13 AC 131 ms
57,432 KB
testcase_14 AC 133 ms
57,412 KB
testcase_15 AC 134 ms
57,436 KB
testcase_16 AC 143 ms
57,452 KB
testcase_17 AC 131 ms
57,528 KB
testcase_18 AC 134 ms
57,584 KB
testcase_19 AC 133 ms
57,552 KB
testcase_20 AC 137 ms
57,380 KB
testcase_21 AC 132 ms
57,412 KB
testcase_22 AC 131 ms
57,624 KB
testcase_23 AC 130 ms
57,468 KB
testcase_24 AC 132 ms
57,348 KB
testcase_25 AC 129 ms
57,440 KB
testcase_26 AC 130 ms
57,624 KB
testcase_27 AC 159 ms
57,444 KB
testcase_28 AC 190 ms
57,444 KB
testcase_29 AC 138 ms
57,684 KB
testcase_30 AC 146 ms
57,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean[] isNotPrime = new boolean[n + 1];
		int[] counts = new int[n + 1];
		Arrays.fill(counts, -1);
		counts[0] = 0;
		for (int i = 2; i <= n; i++) {
		    if (!isNotPrime[i]) {
		        for (int j = 2; j * i <= n; j++) {
		            isNotPrime[j * i] = true;
		        }
		        for (int j = n; j - i >= 0; j--) {
		            if (counts[j - i] == -1) {
		                continue;
		            }
		            counts[j] = Math.max(counts[j], counts[j - i] + 1);
		        }
		    }
		}
		System.out.println(counts[n]);
	}
}
0