結果
問題 | No.7 プライムナンバーゲーム |
ユーザー | rf141 |
提出日時 | 2015-12-20 09:40:31 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 228 ms / 5,000 ms |
コード長 | 1,177 bytes |
コンパイル時間 | 2,358 ms |
コンパイル使用メモリ | 79,076 KB |
実行使用メモリ | 54,416 KB |
最終ジャッジ日時 | 2024-04-09 03:54:01 |
合計ジャッジ時間 | 6,196 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 127 ms
54,144 KB |
testcase_01 | AC | 127 ms
54,228 KB |
testcase_02 | AC | 228 ms
54,252 KB |
testcase_03 | AC | 151 ms
54,160 KB |
testcase_04 | AC | 145 ms
53,944 KB |
testcase_05 | AC | 147 ms
53,980 KB |
testcase_06 | AC | 170 ms
54,200 KB |
testcase_07 | AC | 162 ms
54,308 KB |
testcase_08 | AC | 157 ms
54,416 KB |
testcase_09 | AC | 182 ms
54,416 KB |
testcase_10 | AC | 130 ms
53,908 KB |
testcase_11 | AC | 151 ms
53,500 KB |
testcase_12 | AC | 204 ms
54,240 KB |
testcase_13 | AC | 209 ms
54,288 KB |
testcase_14 | AC | 228 ms
54,316 KB |
testcase_15 | AC | 223 ms
54,212 KB |
testcase_16 | AC | 224 ms
54,132 KB |
ソースコード
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; judge[1] = 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; } }