結果

問題 No.7 プライムナンバーゲーム
ユーザー kuramukuramu
提出日時 2016-01-22 23:34:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 98 ms / 5,000 ms
コード長 1,157 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 78,568 KB
実行使用メモリ 52,084 KB
最終ジャッジ日時 2024-04-09 03:54:30
合計ジャッジ時間 4,135 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
50,348 KB
testcase_01 AC 49 ms
50,256 KB
testcase_02 AC 93 ms
51,768 KB
testcase_03 AC 78 ms
51,572 KB
testcase_04 AC 65 ms
50,536 KB
testcase_05 AC 64 ms
50,556 KB
testcase_06 AC 85 ms
51,892 KB
testcase_07 AC 81 ms
51,536 KB
testcase_08 AC 80 ms
51,892 KB
testcase_09 AC 89 ms
51,696 KB
testcase_10 AC 51 ms
50,384 KB
testcase_11 AC 98 ms
52,084 KB
testcase_12 AC 86 ms
51,688 KB
testcase_13 AC 85 ms
51,800 KB
testcase_14 AC 87 ms
51,696 KB
testcase_15 AC 89 ms
51,784 KB
testcase_16 AC 91 ms
51,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
	      BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in));
	      try {
	    	 int N = Integer.parseInt(stdReader.readLine());
	    	 boolean[] dp = new boolean[N+1];
	    	 boolean[] prime = new boolean[N+1];
	    	 ArrayList<Integer> primeList = new ArrayList<>();
	    	 
	    	 Arrays.fill(prime, true);
	    	 prime[0] = false;
	    	 prime[1] = false;
	    	 
	    	 for(int i=2;i<N+1;i++){
	    		 if(prime[i]){
	    			 primeList.add(i);
	    			 for(int j=i*2;j<N+1;j+=i){
	    				 prime[j] = false;
	    			 }
	    		 }
	    	 }
	    	 dp[0] = true;
	    	 dp[1] = true;	    	 
	    	 for(int i=2;i<N+1;i++){
	    		 for(int j=0;j<primeList.size();j++){
	    			 if(i-primeList.get(j)<0) break;
	    			 dp[i] = !dp[i-primeList.get(j)];
	    			 if(dp[i]) break;
	    		 }
	    	 }
	    	 System.out.println(dp[N]?"Win":"Lose");
	    	 
	      } catch (IOException e) {
			e.printStackTrace();
	      }
	}	
}
0