結果

問題 No.7 プライムナンバーゲーム
ユーザー shinwisteriashinwisteria
提出日時 2017-03-28 11:31:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 179 ms / 5,000 ms
コード長 773 bytes
コンパイル時間 3,570 ms
コンパイル使用メモリ 78,976 KB
実行使用メモリ 54,508 KB
最終ジャッジ日時 2024-04-09 04:12:54
合計ジャッジ時間 7,102 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
54,264 KB
testcase_01 AC 131 ms
54,264 KB
testcase_02 AC 179 ms
54,288 KB
testcase_03 AC 150 ms
54,136 KB
testcase_04 AC 143 ms
54,376 KB
testcase_05 AC 142 ms
54,072 KB
testcase_06 AC 159 ms
54,264 KB
testcase_07 AC 166 ms
54,172 KB
testcase_08 AC 154 ms
54,508 KB
testcase_09 AC 163 ms
54,068 KB
testcase_10 AC 131 ms
54,196 KB
testcase_11 AC 160 ms
54,332 KB
testcase_12 AC 170 ms
54,128 KB
testcase_13 AC 172 ms
54,384 KB
testcase_14 AC 176 ms
54,116 KB
testcase_15 AC 173 ms
54,256 KB
testcase_16 AC 171 ms
54,260 KB
権限があれば一括ダウンロードができます

ソースコード

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