結果
問題 |
No.7 プライムナンバーゲーム
|
ユーザー |
![]() |
提出日時 | 2018-02-14 19:00:06 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 913 bytes |
コンパイル時間 | 3,875 ms |
コンパイル使用メモリ | 78,004 KB |
実行使用メモリ | 41,872 KB |
最終ジャッジ日時 | 2024-12-23 00:52:42 |
合計ジャッジ時間 | 7,099 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 WA * 1 RE * 14 |
ソースコード
import java.util.ArrayList; import java.util.Scanner; public class No7 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); boolean dp[] = new boolean[10010]; dp[0] = false; dp[1] = false; dp[2] = true; dp[3] = true; dp[4] = true; dp[5] = true; ArrayList<Integer> sosuu = new ArrayList<Integer>(); for(int i = 2;i <= N;i++) { sosuu.add(i); } for(int x = 6;x <= N;x++) { for(int i = 0;sosuu.get(i) <= Math.sqrt(x);i++) { for(int j = 2;(sosuu.get(i) * j) <= x;j++) { if(sosuu.indexOf(sosuu.get(i) * j) != -1) { sosuu.remove(sosuu.indexOf(sosuu.get(i) * j)); } } } dp[x] = true; for(int i = 0;i < sosuu.size();i++) { if(dp[x - sosuu.get(i)]) { dp[x] = false; break; } } } if(dp[N]) { System.out.println("Win"); }else { System.out.println("Lose"); } } }