結果

問題 No.7 プライムナンバーゲーム
ユーザー rf141rf141
提出日時 2015-12-20 09:35:43
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,159 bytes
コンパイル時間 2,722 ms
コンパイル使用メモリ 79,728 KB
実行使用メモリ 57,940 KB
最終ジャッジ日時 2023-10-17 14:05:59
合計ジャッジ時間 5,957 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
56,040 KB
testcase_01 AC 124 ms
57,400 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 138 ms
57,488 KB
testcase_05 WA -
testcase_06 AC 152 ms
57,496 KB
testcase_07 AC 148 ms
57,332 KB
testcase_08 AC 146 ms
57,652 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 150 ms
55,804 KB
testcase_12 AC 170 ms
57,272 KB
testcase_13 AC 174 ms
57,628 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 179 ms
56,892 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 = 3; i <= n; i+=2){
			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