結果

問題 No.12 限定された素数
ユーザー purple_jwlpurple_jwl
提出日時 2015-03-07 15:53:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 1,285 bytes
コンパイル時間 1,144 ms
コンパイル使用メモリ 144,712 KB
実行使用メモリ 8,528 KB
最終ジャッジ日時 2023-08-15 22:51:01
合計ジャッジ時間 3,863 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
8,208 KB
testcase_01 AC 59 ms
8,432 KB
testcase_02 AC 59 ms
8,208 KB
testcase_03 AC 57 ms
8,308 KB
testcase_04 AC 58 ms
8,248 KB
testcase_05 AC 59 ms
8,528 KB
testcase_06 AC 58 ms
8,376 KB
testcase_07 AC 59 ms
8,204 KB
testcase_08 AC 59 ms
8,248 KB
testcase_09 AC 58 ms
8,240 KB
testcase_10 AC 59 ms
8,212 KB
testcase_11 AC 61 ms
8,204 KB
testcase_12 AC 61 ms
8,436 KB
testcase_13 AC 61 ms
8,232 KB
testcase_14 AC 60 ms
8,216 KB
testcase_15 AC 60 ms
8,284 KB
testcase_16 AC 62 ms
8,264 KB
testcase_17 AC 60 ms
8,212 KB
testcase_18 AC 59 ms
8,220 KB
testcase_19 AC 59 ms
8,436 KB
testcase_20 AC 58 ms
8,372 KB
testcase_21 AC 59 ms
8,292 KB
testcase_22 AC 58 ms
8,300 KB
testcase_23 AC 59 ms
8,284 KB
testcase_24 AC 59 ms
8,216 KB
testcase_25 AC 59 ms
8,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

const int MAX = 5000000;

bool isPrime[MAX + 1];

void sieve(int N){
  for(int i = 0; i <= N; i++) {
    isPrime[i] = true;
  }
  
  isPrime[0] = isPrime[1] = false;

  for(int i = 2; i <= N; i++) {
    if(!isPrime[i]) continue;
    for(int j = i + i; j <= N; j += i) {
      isPrime[j] = false;
    }
  }
}

int func(int v) {
  int res = 0;
  while(v) {
    int tmp = v % 10;
    v /= 10;
    res |= (1 << tmp);
  }
  return res;
}

int main() {
  // ios_base::sync_with_stdio(false);
  sieve(MAX);

  int N;
  cin >> N;

  int ok = 0;
  rep(i, N) {
    int A;
    cin >> A;
    ok |= (1 << A);
  }

  int ng = ((1 << 10) - 1) ^ ok;
  int ans = -1;
  int K = -1;
  int flg = 0;
  for(int i = 1; i <= MAX; i++) {
    if(K == -1) K = i;

    if(isPrime[i]) flg |= func(i);
    
    if(flg & ng) {
      K = -1;
      flg = 0;
    }
    else if(flg == ok) {
      ans = max(ans, i - K);
    }
  }

  cout << ans << endl;
  
  return 0;
}
0