結果
| 問題 |
No.12 限定された素数
|
| コンテスト | |
| ユーザー |
horizon4096
|
| 提出日時 | 2018-01-11 00:32:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 407 ms / 5,000 ms |
| コード長 | 1,652 bytes |
| コンパイル時間 | 839 ms |
| コンパイル使用メモリ | 72,424 KB |
| 実行使用メモリ | 8,700 KB |
| 最終ジャッジ日時 | 2024-11-24 10:02:52 |
| 合計ジャッジ時間 | 11,522 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:43:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
43 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
main.cpp:46:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
46 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
ソースコード
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
const int iinf = 1 << 29;
const long long linf = 1ll << 61;
#define dump(x) cerr << #x << " : " << x << '\n'
#define MOD(x, y) (((y) + (x) % (y)) % (y))
int N;
bool A[10];
bool erat[5000001];
int isused(int n, int d) {
while (n != 0) {
if (n % 10 == d) return 1;
n /= 10;
}
return 0;
}
int main(int argc, char* argv[])
{
scanf("%d", &N);
for (int i = 0; i < N; i++) {
int a;
scanf("%d", &a);
A[a] = true;
}
fill(erat + 2, erat + 5000001, true);
for (int i = 2; i <= 5000000; i++) {
if (!erat[i]) continue;
for (int j = 2 * i; j <= 5000000; j += i) {
erat[j] = false;
}
}
int used[10] = {};
int k = 1, l = 1;
int ans = -1;
while (true) {
while (true) {
bool f1 = true;
for (int i = 0; i < 10; i++) {
if ((used[i] > 0) && !A[i]) f1 = false;
}
bool f2 = true;
for (int i = 0; i < 10; i++) {
if ((used[i] == 0) && A[i]) f2 = false;
}
if (f1 & f2) {
ans = max(ans, l - k);
break;
} else if (!f2) {
break;
}
if (erat[k]) {
for (int i = 0; i < 10; i++) {
used[i] -= isused(k, i);
}
}
k++;
}
l++;
if (l > 5000000) break;
if (erat[l]) {
for (int i = 0; i < 10; i++) {
used[i] += isused(l, i);
}
}
}
printf("%d\n", ans);
return 0;
}
horizon4096