結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
kyawashell
|
| 提出日時 | 2017-12-08 09:57:49 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 150 ms / 5,000 ms |
| コード長 | 963 bytes |
| コンパイル時間 | 2,320 ms |
| コンパイル使用メモリ | 77,976 KB |
| 実行使用メモリ | 41,484 KB |
| 最終ジャッジ日時 | 2024-10-01 16:07:43 |
| 合計ジャッジ時間 | 4,886 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
import java.util.*;
class Main{
static void gethurui(boolean hurui[],int n){
hurui[0] = hurui[1] = false;
for(int i = 2;i <= n;i++)
hurui[i] = true;
for(int i = 2;i <= (int)(Math.sqrt(n) + 0.1);i++){
if(!hurui[i])
continue;
for(int j = i * 2;j <= n;j += i){
hurui[j] = false;
}
}
}
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
scan.close();
boolean[] hurui = new boolean[n + 1];
gethurui(hurui,n);
ArrayList<Integer> p = new ArrayList<Integer>();
for(int i = 0;i <= n;i++){
if(hurui[i])
p.add(i);
}
boolean[] dp = new boolean[n + 1];
dp[0] = dp[1] = true;
for(int i = 2;i <= n;i++){
boolean f = false;
int j = 0;
while(j < p.size() && p.get(j) <= i){
if(!dp[i - p.get(j)]){
f = true;
break;
}
j++;
}
dp[i] = f;
}
if(dp[n])
System.out.println("Win");
else
System.out.println("Lose");
}
}
kyawashell