結果

問題 No.7 プライムナンバーゲーム
ユーザー takeya_okinotakeya_okino
提出日時 2019-09-14 22:46:24
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 557 bytes
コンパイル時間 1,899 ms
コンパイル使用メモリ 72,004 KB
実行使用メモリ 56,440 KB
最終ジャッジ日時 2023-09-20 20:58:55
合計ジャッジ時間 7,352 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
56,096 KB
testcase_01 WA -
testcase_02 AC 500 ms
56,440 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 187 ms
56,312 KB
testcase_08 WA -
testcase_09 AC 281 ms
55,516 KB
testcase_10 AC 117 ms
55,328 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 498 ms
56,188 KB
testcase_15 AC 480 ms
56,132 KB
testcase_16 AC 449 ms
56,328 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