結果

問題 No.7 プライムナンバーゲーム
ユーザー jp_stejp_ste
提出日時 2016-02-03 13:00:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 152 ms / 5,000 ms
コード長 698 bytes
コンパイル時間 2,032 ms
コンパイル使用メモリ 74,364 KB
実行使用メモリ 54,572 KB
最終ジャッジ日時 2024-04-09 03:54:59
合計ジャッジ時間 5,216 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
54,136 KB
testcase_01 AC 122 ms
54,148 KB
testcase_02 AC 147 ms
54,204 KB
testcase_03 AC 133 ms
53,964 KB
testcase_04 AC 128 ms
54,572 KB
testcase_05 AC 127 ms
53,988 KB
testcase_06 AC 133 ms
54,072 KB
testcase_07 AC 136 ms
54,128 KB
testcase_08 AC 129 ms
53,840 KB
testcase_09 AC 136 ms
54,128 KB
testcase_10 AC 125 ms
53,988 KB
testcase_11 AC 131 ms
54,168 KB
testcase_12 AC 142 ms
53,952 KB
testcase_13 AC 143 ms
53,968 KB
testcase_14 AC 152 ms
54,120 KB
testcase_15 AC 149 ms
54,252 KB
testcase_16 AC 145 ms
54,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		scan.close();
		
		boolean prime[] = new boolean[N+1];
		for(int i=2; i<=N; i++) {
			prime[i] = true;
		}
		
		for(int i=2; i<Math.sqrt(N); i++){
			if(prime[i]) {
				for(int j=i+i; j<=N; j+=i) {
					prime[j] = false;
				}
			}
		}
		
		boolean dp[] = new boolean[N+1];
		
		for(int i=4; i<=N; i++) {
			for(int j=i; j>=2; j--) {
				if(prime[j]) {	
					if(i-j >= 2 && !dp[i-j]) {
						dp[i] = true;
						break;
					}
				}
			}
		}
		
		if(dp[N]) {
			System.out.println("Win");
		} else {
			System.out.println("Lose");
		}
	}
}
0