結果

問題 No.7 プライムナンバーゲーム
ユーザー kuramubonnkuramubonn
提出日時 2023-02-03 19:49:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 974 ms / 5,000 ms
コード長 910 bytes
コンパイル時間 2,072 ms
コンパイル使用メモリ 73,744 KB
実行使用メモリ 56,440 KB
最終ジャッジ日時 2023-09-15 15:06:39
合計ジャッジ時間 10,472 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,616 KB
testcase_01 AC 127 ms
56,156 KB
testcase_02 AC 974 ms
55,988 KB
testcase_03 AC 164 ms
55,904 KB
testcase_04 AC 135 ms
55,924 KB
testcase_05 AC 133 ms
55,860 KB
testcase_06 AC 317 ms
55,988 KB
testcase_07 AC 246 ms
55,924 KB
testcase_08 AC 175 ms
53,952 KB
testcase_09 AC 440 ms
55,596 KB
testcase_10 AC 128 ms
56,440 KB
testcase_11 AC 249 ms
55,916 KB
testcase_12 AC 693 ms
56,032 KB
testcase_13 AC 734 ms
55,604 KB
testcase_14 AC 974 ms
55,360 KB
testcase_15 AC 923 ms
55,812 KB
testcase_16 AC 844 ms
55,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sub s = new sub();
		int num = sc.nextInt();
		if(num < 3) {
			System.out.println("Lose");
			return;
		}
		Boolean[] ju = new Boolean [num - 1];
		ju[0] = false ; ju[1] = false;
		for(int i = 4 ; i <= num ; i++) {
			Boolean flug = false;
			for(int j = 2 ; j < i ; j = s.nextprime(j)) {
				if(i - j < 2) continue;
				if(ju [(i - j) - 2] == false) {
					flug = true;
					break;
				}
			}
			ju[i - 2] = flug;
		}
		if(ju[num - 2] == true)System.out.println("Win");
		else System.out.println("Lose");
	}
}
class sub{
	int nextprime(int num) {
		if(num == 2)return 3;
		Boolean flug;
		for(int i = num + 2 ; ; i = i+2 ) {
			flug = true;
			for(int j = 2 ; j <= Math.sqrt(i) ; j++) {
				if(i % j == 0) {
					flug = false;
					break;
				}
			}
			if(flug == true)return i;
		}
	}
}
0