結果

問題 No.7 プライムナンバーゲーム
ユーザー holegumaholeguma
提出日時 2015-07-26 04:01:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 93 ms / 5,000 ms
コード長 622 bytes
コンパイル時間 2,012 ms
コンパイル使用メモリ 78,208 KB
実行使用メモリ 51,228 KB
最終ジャッジ日時 2024-04-09 03:48:08
合計ジャッジ時間 4,015 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
50,292 KB
testcase_01 AC 50 ms
50,060 KB
testcase_02 AC 93 ms
51,156 KB
testcase_03 AC 61 ms
50,856 KB
testcase_04 AC 52 ms
50,308 KB
testcase_05 AC 52 ms
50,292 KB
testcase_06 AC 73 ms
51,060 KB
testcase_07 AC 71 ms
51,172 KB
testcase_08 AC 68 ms
50,520 KB
testcase_09 AC 81 ms
51,200 KB
testcase_10 AC 50 ms
50,012 KB
testcase_11 AC 70 ms
51,196 KB
testcase_12 AC 84 ms
51,204 KB
testcase_13 AC 84 ms
51,180 KB
testcase_14 AC 92 ms
51,228 KB
testcase_15 AC 91 ms
51,060 KB
testcase_16 AC 89 ms
50,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.Arrays;

class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
boolean[] p=new boolean[10001];
Arrays.fill(p,true);
p[0]=false;
p[1]=false;
for(int i=2;i<=Math.sqrt(10000);i++){
if(p[i]){
for(int j=i+i;j<=10000;j+=i){
p[j]=false;
}
}
}
while((line=br.readLine())!=null){
int n=Integer.parseInt(line);
int[] dp=new int[10001];
dp[0]=0;
dp[1]=0;
for(int i=2;i<=n;i++){
for(int j=2;j<=i;j++){
if(p[i-j]&&dp[j]==0){
dp[i]=1;
break;
}
}
}
System.out.println(dp[n]==1?"Win":"Lose");
}
}
}
0