結果

問題 No.7 プライムナンバーゲーム
ユーザー shinwisteria
提出日時 2017-03-28 11:31:29
言語 Java
(openjdk 23)
結果
AC  
実行時間 169 ms / 5,000 ms
コード長 773 bytes
コンパイル時間 3,261 ms
コンパイル使用メモリ 78,576 KB
実行使用メモリ 41,752 KB
最終ジャッジ日時 2024-10-01 15:57:22
合計ジャッジ時間 6,492 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class PrimeNumberGame {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		s.close();
		ArrayList<Integer> p = new ArrayList<>();
		p.add(2);
		for(int i = 3;i <= N;i++){
			int a = 1;
			for(int j = 0;j < p.size();j++){
				if(i % p.get(j) == 0){
					a = 0;
					break;
				}
			}
			if(a == 1){
				p.add(i);
			}
			
		}
		int[] root = new int[N+1];
		root[0] = 1;
		root[1] = 1;
		for(int i = 2;i <= N;i++){
			for(int j:p){
				if(i-j >= 0 && root[i-j] == 0){
					root[i] = 1;
					break;
				}
			}
			//System.out.println(i + "  " + root[i]);
		}
		if(root[N] == 1){
			System.out.println("Win");
		}else{
			System.out.println("Lose");
		}

	}

}
0