結果

問題 No.12 限定された素数
ユーザー kou6839kou6839
提出日時 2014-12-27 18:54:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 233 ms / 5,000 ms
コード長 1,256 bytes
コンパイル時間 1,924 ms
コンパイル使用メモリ 74,668 KB
実行使用メモリ 68,420 KB
最終ジャッジ日時 2023-08-15 22:29:40
合計ジャッジ時間 8,989 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 215 ms
67,836 KB
testcase_01 AC 216 ms
67,612 KB
testcase_02 AC 206 ms
67,512 KB
testcase_03 AC 222 ms
68,172 KB
testcase_04 AC 214 ms
67,852 KB
testcase_05 AC 223 ms
67,636 KB
testcase_06 AC 217 ms
67,868 KB
testcase_07 AC 224 ms
68,176 KB
testcase_08 AC 216 ms
67,436 KB
testcase_09 AC 214 ms
67,300 KB
testcase_10 AC 222 ms
67,672 KB
testcase_11 AC 230 ms
67,740 KB
testcase_12 AC 224 ms
67,808 KB
testcase_13 AC 213 ms
67,512 KB
testcase_14 AC 233 ms
68,100 KB
testcase_15 AC 222 ms
68,420 KB
testcase_16 AC 215 ms
67,552 KB
testcase_17 AC 204 ms
67,644 KB
testcase_18 AC 215 ms
67,688 KB
testcase_19 AC 214 ms
67,792 KB
testcase_20 AC 217 ms
67,152 KB
testcase_21 AC 214 ms
67,904 KB
testcase_22 AC 218 ms
67,712 KB
testcase_23 AC 220 ms
67,876 KB
testcase_24 AC 216 ms
67,436 KB
testcase_25 AC 221 ms
68,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.*;
import java.util.*;

class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] num = new int[n];
        for(int i=0;i<n;i++){
        	num[i]=sc.nextInt();
        }
        ArrayList<Integer> sosuu = new ArrayList<>();
        sosuu.add(0);
        boolean[] sosu=new boolean[5000001];
        for(int i=2;i<=5000000;i++){
        	if(!sosu[i]){
        		sosuu.add(i);
        		for(int j=i*2;j<=5000000;j+=i){
        			sosu[j]=true;
        		}
        	}
        }
        sosuu.add(5000001);
        int target=0;
        for(int i=0;i<n;i++){
        	target |= (1<<num[i]);
        }
        
        int rou=1;
        int hi = 1;
        int cur =0;
        int ans=-1;
        for(int i=1;i<sosuu.size()-1;i++){
        	int temp = sosuu.get(i);
        	int temp1=0;
        	while(temp>0){
        		temp1 |=(1<<(temp%10));
        		temp/=10;
        	}
        	cur |= temp1;
        	hi=i;
        	if(target==cur){
        		ans=Math.max(ans, sosuu.get(hi+1)-sosuu.get(rou-1)-2);
        	}else if((target|cur)-target>0){
        		rou=hi=i+1;
        		cur=0;
        	}
        }
        System.out.println(ans);
        
    }
}
0