結果

問題 No.7 プライムナンバーゲーム
ユーザー HimatsubushinHimatsubushin
提出日時 2021-01-15 08:59:31
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,345 bytes
コンパイル時間 2,239 ms
コンパイル使用メモリ 104,312 KB
実行使用メモリ 25,108 KB
最終ジャッジ日時 2023-08-16 16:52:17
合計ジャッジ時間 10,669 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
21,644 KB
testcase_01 AC 57 ms
21,712 KB
testcase_02 AC 57 ms
21,608 KB
testcase_03 AC 58 ms
23,676 KB
testcase_04 AC 57 ms
21,644 KB
testcase_05 AC 64 ms
21,644 KB
testcase_06 AC 57 ms
23,776 KB
testcase_07 AC 57 ms
21,552 KB
testcase_08 AC 57 ms
21,620 KB
testcase_09 AC 382 ms
21,560 KB
testcase_10 AC 57 ms
23,704 KB
testcase_11 AC 57 ms
23,748 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

namespace No._07
{
    class Program
    {
        static List<int> prime = new List<int>();

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            primeCheck(n);

            if (judgmentCheck(n))
            {
                Console.WriteLine("Win");
            }
            else
            {
                Console.WriteLine("Lose");
            }
        }

        static void primeCheck(int n)
        {
            bool[] data = Enumerable.Repeat(true, n + 1).ToArray();

            for (int i = 4; i <= n; i += 2)
                data[i] = false;

            for (int i = 3; i <= (int)Math.Sqrt((double)n); i += 2)
                for (int j = 2; i * j <= n; j++)
                    data[i * j] = false;

            for (int i = n; i >= 2; i--)
                if (data[i])
                    prime.Add(i);

            return;
        }

        static bool judgmentCheck(int n)
        {
            if (n > 1)
            {
                foreach (int a in prime)
                    if (n >= a)
                        if (!judgmentCheck(n - a))
                            return true;
                return false;
            }
            else
                return true;
        }
    }
}
0