結果

問題 No.12 限定された素数
ユーザー tarakojo1019tarakojo1019
提出日時 2021-01-18 17:41:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 203 ms / 5,000 ms
コード長 1,512 bytes
コンパイル時間 1,281 ms
コンパイル使用メモリ 122,744 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-21 01:01:08
合計ジャッジ時間 6,206 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
4,384 KB
testcase_01 AC 122 ms
4,384 KB
testcase_02 AC 87 ms
4,504 KB
testcase_03 AC 108 ms
4,380 KB
testcase_04 AC 107 ms
4,384 KB
testcase_05 AC 132 ms
4,384 KB
testcase_06 AC 203 ms
4,380 KB
testcase_07 AC 178 ms
4,380 KB
testcase_08 AC 129 ms
4,380 KB
testcase_09 AC 148 ms
4,380 KB
testcase_10 AC 100 ms
4,380 KB
testcase_11 AC 156 ms
4,384 KB
testcase_12 AC 178 ms
4,384 KB
testcase_13 AC 191 ms
4,380 KB
testcase_14 AC 128 ms
4,384 KB
testcase_15 AC 190 ms
4,380 KB
testcase_16 AC 149 ms
4,380 KB
testcase_17 AC 84 ms
4,380 KB
testcase_18 AC 65 ms
4,380 KB
testcase_19 AC 65 ms
4,384 KB
testcase_20 AC 89 ms
4,380 KB
testcase_21 AC 129 ms
4,380 KB
testcase_22 AC 86 ms
4,384 KB
testcase_23 AC 84 ms
4,380 KB
testcase_24 AC 86 ms
4,380 KB
testcase_25 AC 133 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<numeric>
#include<cstring>
#include<random>
#include<array>
#include<fstream>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<queue>

/*
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) std::cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", (double)v)

template<typename A, typename B>void mins(A& a, const B& b) { a = min(a, (A)b); };
template<typename A, typename B>void maxs(A& a, const B& b) { a = max(a, (A)b); };


int main() {

	ll N; cin >> N;
	unordered_set<ll> s;
	REP(i, 0, N) {
		ll a; cin >> a;
		s.insert(a);
	}

	vector<bool> E(5000001, true);
	E[0] = false;
	E[1] = false;
	REP(i, 2, 5000001) {
		if (!E[i]) continue;
		for (ll j = 2; i * j < E.size(); ++j) E[i * j] = false;
	}

	ll ans = -1;
	
	ll R = 1;
	REP(L, 1, 5000001) {
		if (L < R) continue;

		unordered_set<ll> tmp;
		for (R = L; R < 5000001; ++R) {
			if (E[R]) {
				ll t = R;
				while (t > 0) {
					if (s.count(t % 10) == 0) goto LOOPEND;
					tmp.insert(t % 10);
					t /= 10;
				}
			}
			if (s.size() == tmp.size())maxs(ans, R - L);
		}
	LOOPEND:
		continue;
	}
	PRI(ans);
	return 0;
}
0