結果

問題 No.12 限定された素数
ユーザー kou6839kou6839
提出日時 2014-11-11 14:49:22
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,143 bytes
コンパイル時間 2,523 ms
コンパイル使用メモリ 78,568 KB
実行使用メモリ 80,892 KB
最終ジャッジ日時 2023-08-30 03:07:52
合計ジャッジ時間 13,234 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 332 ms
76,988 KB
testcase_01 WA -
testcase_02 AC 331 ms
77,548 KB
testcase_03 WA -
testcase_04 AC 341 ms
77,648 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 343 ms
77,480 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 322 ms
77,028 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 334 ms
77,628 KB
testcase_21 WA -
testcase_22 AC 328 ms
77,332 KB
testcase_23 AC 333 ms
77,340 KB
testcase_24 AC 332 ms
77,280 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 

public class Main {
	static boolean check(int a,String b){
		String c=a+"";
		for(int i=0;i<b.length();i++ ){
			if( !c.contains(b.charAt(i)+"") ) return false;
		}
		for(int i=0;i<c.length();i++){
			if( !b.contains(c.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();
		while(t<size){
			if(check(sosuu.get(t),a)){
				if(!(t==size-1)){
					ans=Math.max(ans, sosuu.get(t+1)-1-(sosuu.get(s)+1));
				}
				else{
					ans=Math.max(ans, 500000-sosuu.get(s)+1);
				}
			}else{
				s=t;
			}
			t++;			
		}
		if(ans==0){
			System.out.println(-1);
		}else{
			System.out.println(ans);
		}
	}
}	
0