結果
| 問題 | No.12 限定された素数 |
| コンテスト | |
| ユーザー |
atetubou
|
| 提出日時 | 2014-11-14 23:35:20 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 1,170 ms / 5,000 ms |
| コード長 | 2,314 bytes |
| 記録 | |
| コンパイル時間 | 1,249 ms |
| コンパイル使用メモリ | 163,020 KB |
| 実行使用メモリ | 15,804 KB |
| 最終ジャッジ日時 | 2024-11-24 07:34:50 |
| 合計ジャッジ時間 | 23,476 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef ll li;
typedef pair<ll,ll> PI;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i, n) rep (i, n)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) (a).begin(),(a).end()
#define FLL(a,b) memset((a),b,sizeof(a))
#define CLR(a) memset((a),0,sizeof(a))
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
#define FORR(it,a) for(__typeof(a.rbegin())it=a.rbegin();it!=a.rend();++it)
template<typename T,typename U> ostream& operator<< (ostream& out, const pair<T,U>& val){return out << "(" << val.F << ", " << val.S << ")";}
template<class T> ostream& operator<< (ostream& out, const vector<T>& val){out << "{";rep(i,SZ(val)) out << (i?", ":"") << val[i];return out << "}";}
#define declare(a,it) __typeof(a) it=a
const double EPS = 1e-8;
const int dx[]={1,0,-1,0,1,1,-1,-1,0};
const int dy[]={0,1,0,-1,-1,1,-1,1,0};
const int MAX_P = 5100000;
bool npr[MAX_P];
int main(int argc, char *argv[])
{
int n;
cin >> n;
vector<int> a(n);
rep(i,n) cin >> a[i];
int appa[10] = {};
rep(i,n) appa[a[i]] = 1;
npr[0] = npr[1] = 1;
vector<int> app[10];
int vis[10] = {};
for(int i = 2; i < MAX_P; ++i){
if(npr[i]) continue;
int t = i;
if(i<=5000000){
while(t){
int mo = t%10;
if(vis[mo] != i)
app[mo].pb(i);
vis[mo] = i;
t /= 10;
}
}
for(int j = i*2; j < MAX_P; j += i)
npr[j] = true;
}
//cerr << "hoge" << endl;
int ans = -1;
int lim = 5e6;
for(int k = 1; k <= lim; ++k){
int l = lim;
bool ok = true;
rep(i,10){
if(appa[i]) continue;
auto it = lower_bound(ALL(app[i]),k);
if(app[i].end() == it)
continue;
l = min(l, *it-1);
}
rep(i,10){
if(!appa[i]) continue;
auto it = upper_bound(ALL(app[i]),k-1);
if(app[i].end() == it || *it > l){
ok = false;
break;
}
}
if(ok){
//cout << k << " " << l << endl;
ans = max(ans, l - k);
}
}
cout << ans << endl;
return 0;
}
atetubou