結果

問題 No.7 プライムナンバーゲーム
ユーザー rf141rf141
提出日時 2015-12-20 09:38:39
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,158 bytes
コンパイル時間 3,909 ms
コンパイル使用メモリ 79,332 KB
実行使用メモリ 42,016 KB
最終ジャッジ日時 2023-10-17 14:06:13
合計ジャッジ時間 7,237 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
41,032 KB
testcase_01 WA -
testcase_02 AC 241 ms
41,508 KB
testcase_03 AC 142 ms
40,388 KB
testcase_04 AC 152 ms
41,452 KB
testcase_05 AC 152 ms
41,216 KB
testcase_06 WA -
testcase_07 AC 168 ms
41,352 KB
testcase_08 WA -
testcase_09 AC 180 ms
40,620 KB
testcase_10 AC 132 ms
41,128 KB
testcase_11 WA -
testcase_12 AC 220 ms
41,644 KB
testcase_13 AC 224 ms
41,620 KB
testcase_14 AC 246 ms
42,016 KB
testcase_15 WA -
testcase_16 AC 244 ms
41,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.math.*;
public class Main{
	public static void main(String... args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		System.out.println(Calc(n));
	}

	public static String Calc(int n){
		LinkedList<Integer> prime = eratosthenes(n);
		boolean[] judge = new boolean[n+1];
		judge[0] = true;
		for(int i = 4; i <= n; i++){
			for(int p:prime){
				if(0<=i-p && !judge[i-p])judge[i] = true;
			}
		}
		return (judge[n])?"Win":"Lose";
	}

	public static LinkedList<Integer> eratosthenes(int n){
		LinkedList<Integer> list = new LinkedList<Integer>();
		LinkedList<Integer> result = new LinkedList<Integer>();
		list.add(2);
		for(int i = 3; i <= n;i+=2){
			list.add(i);
		}

		double limit = Math.sqrt(n);
		double  head = 0.0;
		int nowHead;
		while(head < limit){
			head = (double)list.get(0);
			nowHead = (int)head;
			result.add(nowHead);
			for(Iterator<Integer> it = list.iterator(); it.hasNext();){
				int num = it.next();
				if(num%nowHead == 0){
					it.remove();
				}
			}
		}

		for(Iterator<Integer> it = list.iterator(); it.hasNext();){
			result.add(it.next());
		}

		return result;
	}


}
0