結果

問題 No.7 プライムナンバーゲーム
ユーザー dogwood0424dogwood0424
提出日時 2017-12-12 21:31:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 159 ms / 5,000 ms
コード長 1,069 bytes
コンパイル時間 3,401 ms
コンパイル使用メモリ 78,892 KB
実行使用メモリ 54,544 KB
最終ジャッジ日時 2024-04-09 04:24:14
合計ジャッジ時間 6,714 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
54,120 KB
testcase_01 AC 126 ms
54,208 KB
testcase_02 AC 158 ms
54,040 KB
testcase_03 AC 140 ms
53,668 KB
testcase_04 AC 130 ms
53,944 KB
testcase_05 AC 130 ms
54,080 KB
testcase_06 AC 148 ms
53,924 KB
testcase_07 AC 147 ms
54,544 KB
testcase_08 AC 145 ms
53,864 KB
testcase_09 AC 153 ms
54,240 KB
testcase_10 AC 123 ms
54,068 KB
testcase_11 AC 150 ms
54,048 KB
testcase_12 AC 156 ms
53,932 KB
testcase_13 AC 156 ms
54,296 KB
testcase_14 AC 159 ms
54,112 KB
testcase_15 AC 159 ms
54,000 KB
testcase_16 AC 159 ms
54,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class No7 {
	public static void main(String[]args) {
		Scanner sc=new Scanner(System.in);
		int n = sc.nextInt();
		//n以下の素数をstackに格納開始
		ArrayList<Integer> stack=new ArrayList<Integer>();	 //スタック
		int max = (int)Math.floor(Math.sqrt(n));
		boolean []boo=new boolean[n+1];
		Arrays.fill(boo,true);
		boo[0]=false;
		boo[1]=false;
		for(int i=2;i<=max;i++) {
			if(boo[i]==true) {
				for(int j=i*2;j<=n;j+=i) {
					boo[j]=false;
				}
			}
		}
		for(int i=0;i<n+1;i++) {
			if(boo[i]==true) {
				stack.add(i);
				}
		}
		//終了


		boolean []v=new boolean[n+1];		//nのとき勝てるならtrue負けるならfalse
		Arrays.fill(v,false);
		v[0]=v[1]=true;
		for(int i=2;i<=n;i++) {
			for(int j=0;j<stack.size();j++) {
				if(stack.get(j)<=i) {
					if(!v[i-stack.get(j)]) {
						v[i]=true;
						break;
					}
				}
			}
			
		}

		if(v[n]) {
			System.out.println("Win");
		}
		else {
			System.out.println("Lose");
		}



		sc.close();
	}

}
0