結果
| 問題 | No.12 限定された素数 |
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2015-05-28 15:56:33 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 81 ms / 5,000 ms |
| コード長 | 861 bytes |
| 記録 | |
| コンパイル時間 | 242 ms |
| コンパイル使用メモリ | 23,552 KB |
| 実行使用メモリ | 21,148 KB |
| 最終ジャッジ日時 | 2024-11-24 08:18:40 |
| 合計ジャッジ時間 | 2,713 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:15:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d", &temp);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#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;
}
FF256grhy