結果

問題 No.7 プライムナンバーゲーム
ユーザー tentententen
提出日時 2020-11-16 18:28:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 166 ms / 5,000 ms
コード長 1,034 bytes
コンパイル時間 3,659 ms
コンパイル使用メモリ 75,972 KB
実行使用メモリ 54,392 KB
最終ジャッジ日時 2024-04-09 05:00:24
合計ジャッジ時間 5,819 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
54,092 KB
testcase_01 AC 130 ms
54,200 KB
testcase_02 AC 159 ms
54,204 KB
testcase_03 AC 155 ms
54,140 KB
testcase_04 AC 137 ms
54,204 KB
testcase_05 AC 137 ms
53,984 KB
testcase_06 AC 155 ms
54,392 KB
testcase_07 AC 153 ms
54,064 KB
testcase_08 AC 154 ms
54,352 KB
testcase_09 AC 161 ms
54,084 KB
testcase_10 AC 134 ms
54,088 KB
testcase_11 AC 166 ms
54,356 KB
testcase_12 AC 156 ms
54,216 KB
testcase_13 AC 159 ms
54,240 KB
testcase_14 AC 166 ms
54,332 KB
testcase_15 AC 163 ms
54,140 KB
testcase_16 AC 157 ms
54,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean[] isNotPrime = new boolean[n + 1];
        ArrayList<Integer> primes = new ArrayList<>();
        for (int i = 2; i <= n; i++) {
            if (!isNotPrime[i]) {
                primes.add(i);
                for (int j = 2; j * i <= n; j++) {
                    isNotPrime[i * j] = true;
                }
            }
        }
        boolean[] isWin = new boolean[n + 1];
        isWin[0] = true;
        isWin[1] = true;
        for (int i = 2; i <= n; i++) {
            for (int x : primes) {
                if (x > i) {
                    break;
                }
                if (!isWin[i - x]) {
                    isWin[i] = true;
                    break;
                }
            }
        }
        if (isWin[n]) {
            System.out.println("Win");
        } else {
            System.out.println("Lose");
        }
    }
}
0