結果
問題 | No.7 プライムナンバーゲーム |
ユーザー | SagToki |
提出日時 | 2018-05-23 14:01:43 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,617 bytes |
コンパイル時間 | 4,787 ms |
コンパイル使用メモリ | 79,656 KB |
実行使用メモリ | 58,024 KB |
最終ジャッジ日時 | 2023-09-11 01:46:50 |
合計ジャッジ時間 | 7,674 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 123 ms
55,172 KB |
testcase_01 | AC | 123 ms
55,620 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 128 ms
55,844 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 147 ms
53,744 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 154 ms
55,716 KB |
testcase_14 | AC | 163 ms
55,628 KB |
testcase_15 | AC | 163 ms
55,660 KB |
testcase_16 | WA | - |
ソースコード
import java.util.Scanner; import java.util.ArrayList; import java.util.Collections; import java.util.InputMismatchException; public class PrimeNumber { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); try{ //Nを入力して範囲が指定通りかを調べる int N = scanner.nextInt(); if(N < 2 || N > 10000){ System.out.println("Nは2以上10000以下の数字で入力してください"); System.exit(0); } //リストに2~Nの素数数を入れる ArrayList<Integer> PrimeNumber = new ArrayList<>(); for(int i = 2; i <= N ; i++){ for(int j = 2 ;( i % j != 0 && j < i) || j == i ; j++){ if(j == i){ PrimeNumber.add(i); } } } //素数を入れたリストを降順でソートする Collections.reverse(PrimeNumber); for(int j = 0 ; j < PrimeNumber.size() ; j++){ if(N - PrimeNumber.get(j) == 2 || N - PrimeNumber.get(j) == 3){ System.out.println("Win"); System.exit(0); } } System.out.println("Lose"); }catch(InputMismatchException e){ System.out.println("数字を入力してください"); }catch(Exception E){ System.out.println("予期せぬエラーです"); } } }