結果

問題 No.458 異なる素数の和
ユーザー fiordfiord
提出日時 2017-02-28 15:56:59
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 884 bytes
コンパイル時間 2,140 ms
コンパイル使用メモリ 102,656 KB
実行使用メモリ 25,472 KB
最終ジャッジ日時 2023-09-18 15:22:03
合計ジャッジ時間 5,488 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
21,480 KB
testcase_01 AC 87 ms
23,448 KB
testcase_02 AC 93 ms
23,460 KB
testcase_03 AC 69 ms
23,560 KB
testcase_04 AC 71 ms
21,488 KB
testcase_05 AC 112 ms
21,644 KB
testcase_06 AC 93 ms
23,520 KB
testcase_07 AC 57 ms
19,508 KB
testcase_08 AC 114 ms
23,492 KB
testcase_09 AC 62 ms
21,440 KB
testcase_10 AC 58 ms
23,576 KB
testcase_11 AC 118 ms
21,464 KB
testcase_12 AC 58 ms
21,652 KB
testcase_13 AC 58 ms
21,460 KB
testcase_14 AC 57 ms
21,532 KB
testcase_15 AC 59 ms
21,732 KB
testcase_16 AC 66 ms
21,520 KB
testcase_17 AC 57 ms
21,456 KB
testcase_18 AC 57 ms
21,496 KB
testcase_19 AC 57 ms
25,472 KB
testcase_20 AC 56 ms
21,616 KB
testcase_21 AC 56 ms
21,504 KB
testcase_22 AC 57 ms
21,576 KB
testcase_23 AC 57 ms
21,564 KB
testcase_24 AC 56 ms
21,476 KB
testcase_25 AC 57 ms
21,652 KB
testcase_26 AC 56 ms
21,444 KB
testcase_27 AC 91 ms
23,584 KB
testcase_28 AC 118 ms
23,652 KB
testcase_29 AC 59 ms
21,484 KB
testcase_30 AC 82 ms
21,480 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.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplicationSharp
{
	class Program
	{
		static void Main(string[] args)
		{
			List<int> prime = new List<int>();
			bool[] check = new bool[20000];
			for (int i = 0; i < 20000; i++) check[i] = true;
			check[0] = check[1] = false;
			for(int i = 2; i < 2000; i++)
			{
				if (check[i] == true)
				{
					prime.Add(i);
					for (int j = 2 * i; j < 20000; j += i) check[j] = false;
				}
			}

			int n = int.Parse(Console.ReadLine());
			int[] dp = new int[n + 1];
			dp[0] = 1;
			for(int i = 0; i < prime.Count(); i++)
			{
				if (n < prime[i]) break;
				for(int j = n-prime[i]; j >= 0; j--)
				{
					if (dp[j] == 0) continue;
					dp[j + prime[i]] = Math.Max(dp[j + prime[i]], dp[j] + 1);
				}
			}
			Console.WriteLine(dp[n] - 1);
		}
	}
}
0