結果

問題 No.12 限定された素数
ユーザー FF256grhyFF256grhy
提出日時 2015-05-28 15:56:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 142 ms / 5,000 ms
コード長 861 bytes
コンパイル時間 687 ms
コンパイル使用メモリ 26,948 KB
実行使用メモリ 22,596 KB
最終ジャッジ日時 2023-08-15 23:00:01
合計ジャッジ時間 4,547 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
22,556 KB
testcase_01 AC 95 ms
22,500 KB
testcase_02 AC 88 ms
22,560 KB
testcase_03 AC 142 ms
22,568 KB
testcase_04 AC 107 ms
22,576 KB
testcase_05 AC 95 ms
22,432 KB
testcase_06 AC 93 ms
22,560 KB
testcase_07 AC 102 ms
22,512 KB
testcase_08 AC 99 ms
22,560 KB
testcase_09 AC 98 ms
22,556 KB
testcase_10 AC 85 ms
22,588 KB
testcase_11 AC 108 ms
22,572 KB
testcase_12 AC 99 ms
22,496 KB
testcase_13 AC 94 ms
22,556 KB
testcase_14 AC 82 ms
22,500 KB
testcase_15 AC 87 ms
22,556 KB
testcase_16 AC 95 ms
22,536 KB
testcase_17 AC 120 ms
22,512 KB
testcase_18 AC 98 ms
22,508 KB
testcase_19 AC 104 ms
22,500 KB
testcase_20 AC 94 ms
22,560 KB
testcase_21 AC 94 ms
22,596 KB
testcase_22 AC 104 ms
22,564 KB
testcase_23 AC 112 ms
22,496 KB
testcase_24 AC 124 ms
22,500 KB
testcase_25 AC 115 ms
22,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

#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;
}
0