結果

問題 No.7 プライムナンバーゲーム
ユーザー takeya_okinotakeya_okino
提出日時 2019-09-14 22:48:12
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 556 bytes
コンパイル時間 1,888 ms
コンパイル使用メモリ 70,808 KB
実行使用メモリ 57,880 KB
最終ジャッジ日時 2023-09-20 21:00:57
合計ジャッジ時間 7,338 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 501 ms
55,360 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 192 ms
55,884 KB
testcase_08 WA -
testcase_09 AC 284 ms
55,356 KB
testcase_10 AC 121 ms
55,600 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 504 ms
55,888 KB
testcase_15 AC 481 ms
55,568 KB
testcase_16 AC 452 ms
55,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] dp = new int[n + 1];
    for(int i = 2; i < n + 1; i++) {
      int p = 0;
      int m = i;
      for(int j = 2; j < n; j++) {
        if((m % j) == 0) {
          if(dp[i - j] == 0) p++;
          while((m % j) == 0) {
            m /= j;
          }
        }
      }
      if(p == 1) dp[i] = 1;
    }
    String ans = "Win";
    if(dp[n] == 0) ans = "Lose";
    System.out.println(ans);
  }
}
0