結果

問題 No.458 異なる素数の和
ユーザー shinwisteriashinwisteria
提出日時 2017-03-30 19:11:28
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 870 bytes
コンパイル時間 3,536 ms
コンパイル使用メモリ 74,912 KB
実行使用メモリ 58,060 KB
最終ジャッジ日時 2023-09-21 08:47:00
合計ジャッジ時間 9,678 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,692 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 153 ms
56,140 KB
testcase_04 AC 151 ms
56,220 KB
testcase_05 AC 168 ms
58,012 KB
testcase_06 WA -
testcase_07 AC 125 ms
55,944 KB
testcase_08 AC 174 ms
58,060 KB
testcase_09 AC 143 ms
55,860 KB
testcase_10 AC 118 ms
56,016 KB
testcase_11 AC 176 ms
55,768 KB
testcase_12 AC 121 ms
54,244 KB
testcase_13 AC 117 ms
56,096 KB
testcase_14 AC 124 ms
55,484 KB
testcase_15 AC 120 ms
55,800 KB
testcase_16 AC 149 ms
56,412 KB
testcase_17 AC 121 ms
55,796 KB
testcase_18 AC 121 ms
56,040 KB
testcase_19 AC 119 ms
56,304 KB
testcase_20 AC 123 ms
56,080 KB
testcase_21 AC 122 ms
55,940 KB
testcase_22 AC 118 ms
55,808 KB
testcase_23 AC 118 ms
56,204 KB
testcase_24 AC 119 ms
55,564 KB
testcase_25 AC 118 ms
56,244 KB
testcase_26 AC 120 ms
55,800 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 132 ms
56,020 KB
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class DifferentSosu {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		s.close();
		ArrayList<Integer> p = new ArrayList<>();
		p.add(2);
		for(int i = 3;i <= N;i++){
			int a = 1;
			for(int j = 0;j < p.size();j++){
				if(i % p.get(j) == 0){
					a = 0;
					break;
				}
			}
			if(a == 1){
				p.add(i);
			}
		}
		int[][] root = new int[N+1][2];
		root[1][0] = -1;
		for(int i = 2;i <= N;i++){
			for(int q:p){
				if(i-q < 0){
					root[i][0] = -1;
					break;
				}else if(root[i-q][0] != -1 && root[i-q][1] < q){
					root[i][0] += root[i-q][0] + 1;
					root[i][1] = q;
					break;
				}
			}
			//System.out.println(root[i][0] + "  " + root[i][1]);
		}
		if(root[N][0] == 0){
			root[N][0] = -1;
		}
		System.out.println(root[N][0]);

	}

}
0