結果

問題 No.12 限定された素数
ユーザー kou6839kou6839
提出日時 2014-11-11 16:02:38
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,291 bytes
コンパイル時間 2,662 ms
コンパイル使用メモリ 86,556 KB
実行使用メモリ 79,880 KB
最終ジャッジ日時 2023-08-30 03:08:27
合計ジャッジ時間 10,675 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 398 ms
79,392 KB
testcase_01 AC 425 ms
79,880 KB
testcase_02 AC 380 ms
78,956 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 

public class Main {
	static boolean finalcheck(String a,String b){
		for(int i=0;i<b.length();i++ ){
			if( !a.contains(b.charAt(i)+"") ) return false;
		}
		return true;
	}
	static boolean check(String a,String b){
		for(int i=0;i<a.length();i++ ){
			if( !b.contains(a.charAt(i)+"") ) return false;
		}
		return true;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String a = "";
		for(int i=0;i<N;i++){
			int temp=sc.nextInt();
			a+=temp;
		}
		ArrayList<Integer> sosuu = new ArrayList<>();
		boolean[] era = new boolean[5000001];
		for(int i=2;i<=5000000;i++){
			if(!era[i]){
				sosuu.add(i);
				for(int j=2*i;j<=5000000;j+=i){
					era[j]=true;
				}
			}
		}
		int t=0;
		int s=0;
		int ans=0;
		int size = sosuu.size();
		String go="";
		while(t<size){
			if(check(sosuu.get(t)+"",a)){
				if(t==size-1){
					ans=Math.max(ans, 5000000-(sosuu.get(s)+1));
					break;
				}else{
					go+=sosuu.get(t);
				}
			}else{
				if(finalcheck(go,a)){
					ans=Math.max(ans, (sosuu.get(t)-1)-(sosuu.get(s)+1));
				}
				s=t;
				go="";
			}
			t++;
		}
		if(ans==0){
			System.out.println(-1);
		}else{
			System.out.println(ans);
		}
	}
}
0