結果

問題 No.7 プライムナンバーゲーム
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-12-03 21:18:37
言語 Java19
(openjdk 21)
結果
AC  
実行時間 313 ms / 5,000 ms
コード長 997 bytes
コンパイル時間 2,909 ms
コンパイル使用メモリ 74,464 KB
実行使用メモリ 56,388 KB
最終ジャッジ日時 2023-07-24 20:41:45
合計ジャッジ時間 7,274 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,652 KB
testcase_01 AC 124 ms
55,876 KB
testcase_02 AC 313 ms
56,144 KB
testcase_03 AC 147 ms
55,888 KB
testcase_04 AC 144 ms
55,700 KB
testcase_05 AC 143 ms
56,052 KB
testcase_06 AC 190 ms
55,776 KB
testcase_07 AC 161 ms
56,168 KB
testcase_08 AC 151 ms
56,136 KB
testcase_09 AC 218 ms
56,012 KB
testcase_10 AC 135 ms
55,784 KB
testcase_11 AC 160 ms
55,952 KB
testcase_12 AC 263 ms
56,276 KB
testcase_13 AC 271 ms
56,324 KB
testcase_14 AC 308 ms
56,384 KB
testcase_15 AC 303 ms
56,388 KB
testcase_16 AC 290 ms
56,352 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 [] b = new boolean [N+1];
        ArrayList<Integer> prime = new ArrayList<Integer>();
        for(int i=2; i<=N; i++){
            if(b[i]==false){
                prime.add(i);
                for(int j=2; j<=N; j++){
                    if(j%i==0){
                        b[j]=true;
                    }
                }
            }
        }
        boolean [] WL = new boolean [N+1];
        WL[0]=WL[1]=true;
        for(int i=4; i<=N; i++){
            for(int j=prime.size()-1; j>=0; j--){
                if(prime.get(j)<i){
                    if(WL[i-prime.get(j)]==false){
                        WL[i]=true;
                    }
                }
            }
        }
        if(WL[N]){
            System.out.println("Win");
        }else{
            System.out.println("Lose");
        }
    }
}
0