package yukicoder; import java.util.*; public class Main{ public static void main(String[] args)throws Exception{ new Main().solve(); } void solve(){ Scanner sc=new Scanner(System.in); int[] d=new int[10]; int n=sc.nextInt(); for(int i=0;i=1){ memo[a%10]++; a/=10; } } if(check(d,memo)==-30){ max=Math.max(i-k,max); }else if(check(d,memo)==-20){ //継続して右側に進む }else if(check(d,memo)==-10){ while(check(d,memo)==-10){ if(primeList[k]){ int b=k; while(b>=1){ memo[b%10]--; b/=10; } } k++; } } } System.out.println(max); } boolean[] primeList(int n){ boolean[] primeList=new boolean[n+1]; Arrays.fill(primeList, true); primeList[0]=primeList[1]=false; for(int i=2;i<=n;i++){ if(primeList[i]==true){ for(int j=2;i*j<=n;j++){ primeList[i*j]=false; } } } return primeList; } int check(int[] d,int[] memo){ for(int i=0;i<10;i++){ if(d[i]==1&&memo[i]==0)return -20; if(d[i]==0&&memo[i]>0)return -10; } return -30; } void tr(Object...o){System.out.println(Arrays.deepToString(o));} }