結果

問題 No.7 プライムナンバーゲーム
ユーザー リチウムリチウム
提出日時 2014-11-16 18:54:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 233 ms / 5,000 ms
コード長 775 bytes
コンパイル時間 2,334 ms
コンパイル使用メモリ 77,624 KB
実行使用メモリ 54,560 KB
最終ジャッジ日時 2024-04-09 03:40:51
合計ジャッジ時間 5,990 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
53,956 KB
testcase_01 AC 124 ms
54,324 KB
testcase_02 AC 230 ms
53,972 KB
testcase_03 AC 150 ms
53,872 KB
testcase_04 AC 140 ms
54,232 KB
testcase_05 AC 143 ms
54,116 KB
testcase_06 AC 176 ms
54,312 KB
testcase_07 AC 170 ms
54,148 KB
testcase_08 AC 155 ms
53,952 KB
testcase_09 AC 191 ms
54,372 KB
testcase_10 AC 123 ms
54,276 KB
testcase_11 AC 172 ms
54,224 KB
testcase_12 AC 207 ms
53,968 KB
testcase_13 AC 212 ms
53,916 KB
testcase_14 AC 233 ms
54,560 KB
testcase_15 AC 225 ms
54,192 KB
testcase_16 AC 228 ms
54,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static List<Integer> primes = new ArrayList<Integer>();

	static void primeget(int n) {
		boolean pc;
		primes.add(2);
		primes.add(3);
		for (int i = 4; i < n; i++) {
			pc = false;
			for (int p = 0; p < primes.size(); p++) {
				if (i % primes.get(p) == 0) {
					pc = true;
					break;
				}
			}
			if (pc == false) {
				primes.add(i);
			}
		}
	}
				
	public static void main(String[] args) {
		Scanner sc=new Scanner (System.in);
		int n=sc.nextInt();
		primeget(n);
		boolean win[]=new boolean[n+1];
		win[0]=win[1]=true;
		for(int i=4;i<=n;i++){
			for(int p:primes){
				if(i-p>=0 && !win[i-p])win[i]=true;
			}
		}
		String s="Lose";
		if(win[n])s="Win";
		System.out.println(s);
	}}
0