結果

問題 No.7 プライムナンバーゲーム
ユーザー しらゆき
提出日時 2015-11-24 21:34:48
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 964 ms / 5,000 ms
コード長 784 bytes
コンパイル時間 889 ms
コンパイル使用メモリ 110,784 KB
実行使用メモリ 21,812 KB
最終ジャッジ日時 2024-10-01 15:37:52
合計ジャッジ時間 7,596 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        var ans = new string[10001];
        ans[0] = ans[1] = "Win";

        for(int i = 2; i <= n; i++)
        {
            ans[i] = "Lose";
            for (int j = 2; j <= i; j++)
            {
                if (IsPrime(j) && ans[i - j] == "Lose")
                {
                    ans[i] = "Win";
                    break;
                }
            }
        }

        Console.WriteLine(ans[n]);
    }

    static bool IsPrime(int a)
    {
        bool b = true;
        for (int i = 2; i * i <= a; i++)
        {
            if (a % i == 0)
            {
                b = false;
                break;
            }
        }
        return b;
    }
}
0