結果

問題 No.7 プライムナンバーゲーム
ユーザー 37zigen37zigen
提出日時 2016-03-09 18:51:31
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,407 bytes
コンパイル時間 2,343 ms
コンパイル使用メモリ 78,896 KB
実行使用メモリ 62,008 KB
最終ジャッジ日時 2023-10-24 21:49:37
合計ジャッジ時間 9,321 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
57,348 KB
testcase_01 AC 135 ms
57,404 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	static ArrayList<Integer> PrimeList=new ArrayList<>();
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		boolean isPrime[]=new boolean[n+1];
		isPrime=isPrime(n);
		//for(int i=0;i<=n;i++){
		//System.out.println("isPrime["+i+"]="+isPrime[i]);
		//}
		PrimeList=PrimeList(n);
		if(judge(n)){
			System.out.println("Win");
		}else{
			System.out.println("Lose");
		}
	}

	public static boolean[] isPrime(int n){
		boolean isPrime[]=new boolean[n+1];
		Arrays.fill(isPrime, true);
		isPrime[0]=false;
		isPrime[1]=false;
		for(int i=2;i<n;i++){
			if(isPrime[i]){
				for(int j=2;j*i<=n;j++){
					isPrime[i*j]=false;
				}
			}
		}
		return isPrime;
	}
	public static ArrayList<Integer> PrimeList(int n){
		ArrayList<Integer> PrimeList=new ArrayList<>();
		boolean[] isPrime=new boolean[n+1];
		isPrime=isPrime(n);
		for(int i=2;i<=n;i++){
			if(isPrime[i]){
				PrimeList.add(i);
			}
		}
		return PrimeList;
	}
	//judge(n)の数字で回って来た時の自分の勝ち負けを調べる。
	public static boolean judge(int n){
		boolean judge=false;
		int p;
		for(int i=0;i<PrimeList.size()&&PrimeList.get(i)<=n;i++){
			p=PrimeList.get(i);
			if(!judge(n-PrimeList.get(i))){
				judge=true;
			}
		}
		if(n==1||n==0)return true;
		return judge;
	}
}
0