結果

問題 No.7 プライムナンバーゲーム
ユーザー zimphazimpha
提出日時 2017-03-24 22:52:50
言語 Java19
(openjdk 21)
結果
AC  
実行時間 78 ms / 5,000 ms
コード長 2,491 bytes
コンパイル時間 2,720 ms
コンパイル使用メモリ 74,956 KB
実行使用メモリ 52,696 KB
最終ジャッジ日時 2023-07-24 20:49:11
合計ジャッジ時間 4,852 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
49,236 KB
testcase_01 AC 40 ms
49,316 KB
testcase_02 AC 78 ms
51,988 KB
testcase_03 AC 69 ms
51,704 KB
testcase_04 AC 49 ms
50,644 KB
testcase_05 AC 46 ms
50,300 KB
testcase_06 AC 73 ms
52,256 KB
testcase_07 AC 69 ms
52,492 KB
testcase_08 AC 71 ms
51,788 KB
testcase_09 AC 75 ms
52,240 KB
testcase_10 AC 39 ms
49,416 KB
testcase_11 AC 70 ms
52,280 KB
testcase_12 AC 74 ms
52,516 KB
testcase_13 AC 76 ms
52,264 KB
testcase_14 AC 75 ms
52,696 KB
testcase_15 AC 78 ms
52,504 KB
testcase_16 AC 76 ms
52,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Chiaki.Hoshinomori
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task007 solver = new Task007();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task007 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            boolean[] mark = new boolean[n + 1];
            List<Integer> pl = new ArrayList<>();
            for (int i = 2; i <= n; ++i) {
                if (!mark[i]) {
                    pl.add(i);
                    for (int j = i; j <= n; j += i) {
                        mark[j] = true;
                    }
                }
            }
            mark[0] = mark[1] = true;
            for (int i = 2; i <= n; ++i) {
                mark[i] = false;
                for (int p : pl) {
                    if (p > i) break;
                    if (!mark[i - p]) {
                        mark[i] = true;
                        break;
                    }
                }
            }
            if (mark[n]) out.println("Win");
            else out.println("Lose");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

0