結果
問題 | No.12 限定された素数 |
ユーザー | not_522 |
提出日時 | 2015-08-19 00:45:24 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 213 ms / 5,000 ms |
コード長 | 2,431 bytes |
コンパイル時間 | 1,665 ms |
コンパイル使用メモリ | 157,552 KB |
実行使用メモリ | 70,628 KB |
最終ジャッジ日時 | 2023-08-15 23:05:45 |
合計ジャッジ時間 | 7,425 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 142 ms
68,892 KB |
testcase_01 | AC | 156 ms
69,100 KB |
testcase_02 | AC | 150 ms
69,616 KB |
testcase_03 | AC | 206 ms
68,908 KB |
testcase_04 | AC | 148 ms
69,332 KB |
testcase_05 | AC | 167 ms
69,088 KB |
testcase_06 | AC | 177 ms
69,192 KB |
testcase_07 | AC | 192 ms
68,924 KB |
testcase_08 | AC | 163 ms
69,772 KB |
testcase_09 | AC | 160 ms
70,116 KB |
testcase_10 | AC | 165 ms
70,628 KB |
testcase_11 | AC | 204 ms
69,628 KB |
testcase_12 | AC | 182 ms
68,968 KB |
testcase_13 | AC | 168 ms
69,772 KB |
testcase_14 | AC | 163 ms
69,220 KB |
testcase_15 | AC | 174 ms
69,388 KB |
testcase_16 | AC | 213 ms
69,188 KB |
testcase_17 | AC | 142 ms
68,612 KB |
testcase_18 | AC | 146 ms
69,128 KB |
testcase_19 | AC | 146 ms
69,040 KB |
testcase_20 | AC | 153 ms
69,168 KB |
testcase_21 | AC | 155 ms
69,160 KB |
testcase_22 | AC | 149 ms
70,472 KB |
testcase_23 | AC | 148 ms
69,384 KB |
testcase_24 | AC | 143 ms
69,104 KB |
testcase_25 | AC | 170 ms
69,776 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; class Prime { private: vector<long long> div; public: Prime(long long n = 0) { for (long long i = 0; i <= n; ++i) div.emplace_back(i); for (long long i = 2; i <= n / i; ++i) if (div[i] == i) { for (long long j = i * i; j <= n; j += i) div[j] = i; } } bool isPrime(long long n) const { if (n <= 1) return false; if (n < (long long)div.size()) return div[n] == n; for (long long i = 2; i <= n / i; ++i) if (n % i == 0) return false; return true; } vector<long long> factor(long long n) const { vector<long long> res; for (long long i = 2; i <= n / i && n >= (long long)div.size(); ++i) { while (n % i == 0) { res.emplace_back(i); n /= i; } } if (n >= max((long long)div.size(), 2ll)) { res.emplace_back(n); } else { while (n > 1) { res.emplace_back(div[n]); n /= div[n]; } } sort(res.begin(), res.end()); return res; } vector<long long> primeFactor(long long n) const { vector<long long> res; for (long long i = 2; i <= n / i && n >= (long long)div.size(); ++i) { if (n % i) continue; res.emplace_back(i); while (n % i == 0) n /= i; } if (n >= max((long long)div.size(), 2ll)) { res.emplace_back(n); } else { while (n > 1) { long long d = div[n]; res.emplace_back(d); while (n % d == 0) n /= d; } } sort(res.begin(), res.end()); return res; } vector<long long> divisor(long long n) const { vector<long long> res; for (long long i = 1; i <= n / i; ++i) { if (n % i == 0) { res.emplace_back(i); if (i != n / i) res.emplace_back(n / i); } } sort(res.begin(), res.end()); return res; } }; int main() { Prime prime(5000000); int n; cin >> n; vector<int> a(n); for (int& i : a) cin >> i; set<int> b(a.begin(), a.end()), c; int res = -1, p = 1; for (int i = 1; i <= 5000000; ++i) { if (!prime.isPrime(i)) continue; bool ok = true; for (int ii = i; ii; ii /= 10) { if (b.count(ii % 10) == 0) ok = false; } if (ok) { for (int ii = i; ii; ii /= 10) c.insert(ii % 10); } else { if (b == c) res = max(res, i - 1 - p); p = i + 1; c = set<int>(); } } if (b == c) res = max(res, 5000000 - p); cout << res << endl; }