結果

問題 No.458 異なる素数の和
ユーザー kuuso1kuuso1
提出日時 2016-12-09 00:06:38
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 1,395 bytes
コンパイル時間 4,520 ms
コンパイル使用メモリ 110,536 KB
実行使用メモリ 22,816 KB
最終ジャッジ日時 2023-09-18 14:46:03
合計ジャッジ時間 6,255 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
20,748 KB
testcase_01 AC 110 ms
20,576 KB
testcase_02 AC 125 ms
20,668 KB
testcase_03 AC 68 ms
20,684 KB
testcase_04 AC 71 ms
20,784 KB
testcase_05 AC 212 ms
20,680 KB
testcase_06 AC 123 ms
22,712 KB
testcase_07 AC 57 ms
22,748 KB
testcase_08 AC 214 ms
22,596 KB
testcase_09 AC 60 ms
22,816 KB
testcase_10 AC 56 ms
20,740 KB
testcase_11 AC 243 ms
20,752 KB
testcase_12 AC 57 ms
22,556 KB
testcase_13 AC 56 ms
20,608 KB
testcase_14 AC 56 ms
20,612 KB
testcase_15 AC 55 ms
20,680 KB
testcase_16 AC 62 ms
20,592 KB
testcase_17 AC 56 ms
20,692 KB
testcase_18 AC 56 ms
22,736 KB
testcase_19 AC 55 ms
18,680 KB
testcase_20 AC 56 ms
20,652 KB
testcase_21 AC 55 ms
20,672 KB
testcase_22 AC 56 ms
20,736 KB
testcase_23 AC 57 ms
22,568 KB
testcase_24 AC 56 ms
20,624 KB
testcase_25 AC 56 ms
20,724 KB
testcase_26 AC 57 ms
20,672 KB
testcase_27 AC 120 ms
20,840 KB
testcase_28 AC 240 ms
20,720 KB
testcase_29 AC 57 ms
20,672 KB
testcase_30 AC 96 ms
20,736 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		bool[] isPrime = new bool[M+1];
		for(int i=2;i<=M;i++) isPrime[i] = true;
		List<int> P = new List<int>();
		for(int i=2;i<=M;i++){
			if(!isPrime[i])continue;
			P.Add(i);
			for(int j=i+i;j<=M;j+=i) isPrime[j] = false;
		}
		
		int[] dp = new int[M+1];
		for(int i=0;i<=M;i++) dp[i] = -1;
		dp[0] = 0;
		foreach(var p in P){
			for(int i=M;i>=0;i--){
				if(dp[i] == -1) continue;
				if(i+p <= M){
					dp[i+p] = Math.Max(dp[i+p],dp[i]+1);
				}
			}
		}
		
		Console.WriteLine(dp[M]);
		
		
		
	}
	int M;
	public Sol(){
		M = ri();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0