結果

問題 No.458 異なる素数の和
コンテスト
ユーザー fiord
提出日時 2017-02-28 15:56:59
言語 C#(csc)
(csc 3.9.0)
コンパイル:
csc -langversion:latest -unsafe -warn:0 -o+ /r:System.Numerics.dll _filename_ -out:a.exe
実行:
/usr/bin/mono a.exe
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 884 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 779 ms
コンパイル使用メモリ 106,240 KB
実行使用メモリ 19,200 KB
最終ジャッジ日時 2026-03-26 12:53:54
合計ジャッジ時間 2,272 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #
raw source code

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