結果
| 問題 | 
                            No.7 プライムナンバーゲーム
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-05-30 22:58:33 | 
| 言語 | C#(csc)  (csc 3.9.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 264 ms / 5,000 ms | 
| コード長 | 2,105 bytes | 
| コンパイル時間 | 1,053 ms | 
| コンパイル使用メモリ | 109,312 KB | 
| 実行使用メモリ | 44,544 KB | 
| 最終ジャッジ日時 | 2024-10-01 16:21:18 | 
| 合計ジャッジ時間 | 6,456 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 17 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
namespace Program
{
    class Program
    {
        static void Main()
        {
            int count = int.Parse(Console.ReadLine());
            Program2 program2=new Program2();
            program2.Calc();
            Console.WriteLine(program2.GetWin(count));
        }
    }
    class Program2
    {
        
        private int[] _win=new int[10001];
        private Sosuu sosuu = new Sosuu();
        public string GetWin(int inNumber)
        {
            return _win[inNumber]==1 ? "Win":"Lose";
        }
        public void Calc()
        {
            _win = _win.Select(x => -1).ToArray();
            _win[0] = 0;
            _win[1] = 0;
            for (int number = 2; number <= 10000; number++)
            {
                _win[number] = Convert.ToInt32(GetWinCalc(number));
            }
        }
        private bool GetWinCalc(int inNumber)
        {
            if (_win[inNumber] != -1)
                return _win[inNumber] == 1;
            List<int> card = sosuu.SosuuList.Where(x => x < inNumber && inNumber - x > 1).ToList();
            if (card.Count == 0)
                return false;
            foreach (int item in card)
            {
                int aiteNo = inNumber - item;
                if (!GetWinCalc(aiteNo))
                    return true;
            }
            return false;
        }
    }
    class Sosuu
    {
        public List<int> SosuuList = new List<int>();
        public Sosuu() {
            SosuuList.Add(2);
            SosuuList.Add(3);
            for (int number = 3;number <= 10000;number++)
            {
                if (number % 2 == 0)
                {
                    continue;
                }
                for (int waruNumbre = 3; waruNumbre < number; waruNumbre++)
                {
                    if (number % waruNumbre == 0)
                    {
                        break;
                    }
                    if(waruNumbre==number-1) SosuuList.Add(number);
                }
            }
        }
    }
}