結果

問題 No.7 プライムナンバーゲーム
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-21 12:21:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 3,656 ms / 5,000 ms
コード長 1,414 bytes
コンパイル時間 2,393 ms
コンパイル使用メモリ 77,752 KB
実行使用メモリ 54,828 KB
最終ジャッジ日時 2024-04-09 03:45:31
合計ジャッジ時間 23,347 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
53,884 KB
testcase_01 AC 129 ms
54,268 KB
testcase_02 AC 3,656 ms
54,332 KB
testcase_03 AC 181 ms
54,244 KB
testcase_04 AC 141 ms
53,920 KB
testcase_05 AC 140 ms
54,024 KB
testcase_06 AC 650 ms
54,428 KB
testcase_07 AC 415 ms
54,136 KB
testcase_08 AC 212 ms
54,248 KB
testcase_09 AC 1,109 ms
54,296 KB
testcase_10 AC 132 ms
54,256 KB
testcase_11 AC 430 ms
53,976 KB
testcase_12 AC 841 ms
54,236 KB
testcase_13 AC 882 ms
53,988 KB
testcase_14 AC 3,643 ms
54,192 KB
testcase_15 AC 3,368 ms
54,828 KB
testcase_16 AC 2,966 ms
53,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
        int n = koko.nextInt();
        int[] prime = new int[1300];
        int ptr = 0;
        prime[ptr++]=2;
        prime[ptr++]=3;
        
        for(int i=5; i<n; i+=2){
            boolean wflag = false;
            for(int j=0; j<ptr; j++){
                if(i%prime[j]==0){
                    wflag=true;
                    break;
                }
            }
            if(!wflag){
                prime[ptr++]=i;
            }
        }
        
        int[] kachi = new int[1400];
        int ka = 0;
        kachi[ka++]=2;
        kachi[ka++]=3;
        for(int i=4; i<=n; i++){
            boolean kflag = false;
loop1:      for(int j=0; j<ptr; j++){
                for(int k=0; k<ka; k++){
                    if(i-prime[j]==kachi[k]){
                        kflag = true;
                        break loop1;
                    }
                }
            }
            if(!kflag){
                kachi[ka++]=i;
            }
        }
        ArrayList<Integer> kac = new ArrayList<Integer>();
        for(int i=0; i<ka; i++){
            kac.add(kachi[i]);
        }
        if(kac.contains(n)){
            System.out.println("Lose");
        }else{
            System.out.println("Win");
        }
    }
}
        
        
0