#include #define MAX 5000000 int check(int); int eq(); int n, digit[10], memo[10], table[MAX + 1]; int main(void) { scanf("%d", &n); int i; for(i = 0; i < n; i++) { int temp; scanf("%d", &temp); digit[temp] = 1; } table[1] = 1; int max = 0, counter = 0; for(i = 1; i <= MAX; i++) { if(table[i] == 0) { int m = i * 2; while(m <= MAX) { table[m] = 1; m += i; } if( ! check(i) ) { counter = 0; int j; for(j = 0; j < 10; j++) { memo[j] = 0; } continue; } } counter++; if( eq() ) { max = (max < counter) ? counter : max; } } printf("%d\n", max - 1); return 0; } int check(int i) { while(i) { if(digit[i % 10] == 0) { return 0; } memo[i % 10] = 1; i /= 10; } return 1; } int eq() { int i; for(i = 0; i < 10; i++) { if(digit[i] != memo[i]) { return 0; } } return 1; }