結果

問題 No.12 限定された素数
ユーザー ym678ym678
提出日時 2016-07-27 12:31:51
言語 Java19
(openjdk 21)
結果
AC  
実行時間 257 ms / 5,000 ms
コード長 1,418 bytes
コンパイル時間 4,429 ms
コンパイル使用メモリ 80,652 KB
実行使用メモリ 68,024 KB
最終ジャッジ日時 2023-08-15 23:32:37
合計ジャッジ時間 10,083 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 247 ms
67,596 KB
testcase_01 AC 248 ms
67,668 KB
testcase_02 AC 238 ms
68,012 KB
testcase_03 AC 246 ms
67,628 KB
testcase_04 AC 246 ms
67,940 KB
testcase_05 AC 257 ms
67,772 KB
testcase_06 AC 247 ms
67,500 KB
testcase_07 AC 255 ms
67,492 KB
testcase_08 AC 245 ms
67,284 KB
testcase_09 AC 245 ms
67,528 KB
testcase_10 AC 257 ms
68,016 KB
testcase_11 AC 249 ms
67,288 KB
testcase_12 AC 248 ms
67,872 KB
testcase_13 AC 245 ms
67,856 KB
testcase_14 AC 256 ms
67,972 KB
testcase_15 AC 248 ms
67,540 KB
testcase_16 AC 245 ms
67,924 KB
testcase_17 AC 237 ms
67,680 KB
testcase_18 AC 246 ms
67,572 KB
testcase_19 AC 246 ms
67,356 KB
testcase_20 AC 248 ms
67,636 KB
testcase_21 AC 247 ms
67,584 KB
testcase_22 AC 251 ms
67,624 KB
testcase_23 AC 248 ms
67,776 KB
testcase_24 AC 242 ms
67,296 KB
testcase_25 AC 249 ms
68,024 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[] A = new int[N];
        
        boolean[] box = new boolean[5000001];
        ArrayList<Integer> sosu = new ArrayList<>();
        Arrays.fill(box,2,box.length,true);
        sosu.add(0);
        for(int i=2 ; i<5000001; i++){
        	if(box[i]){
        		sosu.add(i);
        		for(int j=i*2; j<5000001; j+=i){
        			box[j] = false;
        		}
        	}
        }
        sosu.add(5000001);
        int tage = 0;
        
        for(int i=0; i<N; i++){
        	A[i] = sc.nextInt();
        	tage |= (1<<A[i]);
        }
        
        int sub;
        int sub_bit = 0;
        int bit = 0;
        int ans = -1;
        int right = 1;
        int left = 1;
  
     
        for(int i=1; i<sosu.size()-1; i++){
        	sub = sosu.get(i);
        	bit = 0;
            while(sub>0){
        	    bit |= (1<<sub%10);
        	    sub /= 10;
        	}
        	    
            sub_bit |= bit;
            right = i;
        	    
        	if(sub_bit == tage){
        	    ans = Math.max(ans,(sosu.get(right+1)-1)-(sosu.get(left-1)+1));
        	}else if((sub_bit|tage) - tage > 0){
        	    left = i+1;
        	    right = i+1;
        	    sub_bit = 0;
            }
        }      
        System.out.println(ans);
    }
}
0