結果

問題 No.7 プライムナンバーゲーム
ユーザー spaciaspacia
提出日時 2016-01-02 08:38:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 91 ms / 5,000 ms
コード長 1,034 bytes
コンパイル時間 2,156 ms
コンパイル使用メモリ 77,408 KB
実行使用メモリ 51,560 KB
最終ジャッジ日時 2024-04-09 03:54:06
合計ジャッジ時間 4,221 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
50,400 KB
testcase_01 AC 54 ms
50,252 KB
testcase_02 AC 90 ms
51,440 KB
testcase_03 AC 63 ms
50,616 KB
testcase_04 AC 57 ms
50,080 KB
testcase_05 AC 57 ms
50,260 KB
testcase_06 AC 81 ms
51,348 KB
testcase_07 AC 83 ms
51,432 KB
testcase_08 AC 78 ms
51,264 KB
testcase_09 AC 84 ms
51,544 KB
testcase_10 AC 53 ms
50,340 KB
testcase_11 AC 75 ms
51,260 KB
testcase_12 AC 88 ms
51,400 KB
testcase_13 AC 87 ms
51,560 KB
testcase_14 AC 91 ms
51,436 KB
testcase_15 AC 82 ms
51,092 KB
testcase_16 AC 90 ms
51,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main7 {
	
	public static void out (Object o) {
		System.out.println(o);
	}
	
	public static boolean[] sieve (int n) {
		boolean[] ret = new boolean[n + 1];
		
		Arrays.fill(ret , true);
		ret[1] = false;
		for (int i = 4; i <= n; i += 2) ret[i] = false;
		for (int i = 3; i * i <= n; i += 2) {
			for (int j = 3; i * j <= n; j += 2) {
				ret[i * j] = false;
			}
		}
		return ret;
	}
	
	public static boolean solve (int n , boolean[] isPrime , boolean[] res) {
		for (int i = 2; i < n; i++) {
			if (!isPrime[i]) continue;
			if (!res[n - i] && n - i != 1) return true;
		}
		return false;
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		boolean[] isPrime = sieve(n);
		boolean[] res = new boolean[n + 1];
		
		res[2] = false;
		for (int i = 3; i <= n; i++) {
			res[i] = solve(i , isPrime , res);
		}
		
		out(res[n] ? "Win" : "Lose");
	}
}
0