結果
| 問題 |
No.2244 Integer Complete
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-10 23:22:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 53 ms / 2,000 ms |
| コード長 | 2,218 bytes |
| コンパイル時間 | 1,731 ms |
| コンパイル使用メモリ | 198,728 KB |
| 最終ジャッジ日時 | 2025-02-11 09:19:01 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 60 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
int main() {
// ok, what can I not do?
// some integer such that
// prime you cannot make at least...
// 1e4 + something to be prime, it's impossible to make
// so can just brute force check 1e4 candidates.
// for each candidate, factorize
int n,m; cin >> n >> m;
vi a(n),b(m);
for(auto& i : a) cin >> i;
for(auto& i : b) cin >> i;
// can make a lot more numbers than I thought
// some prime such that it's not within those and not within those?
// actually a bit like convolution.
// but multiplicative.
// answer not bigger than 1e9+7.
// if you just constantly do the least thing not being able
// ok, a prime number has to be made by 1 p, or p 1.
// so if there's some gap, than immediately smaller than the gap you win
// everything up to that can be made
vi cnt(max(*max_element(all(a)), *max_element(all(b))) + 100);
for(int i : a) cnt[i]++;
for(int j : b) cnt[j]++;
ll i=1;
if(cnt[1]==2) {
while(cnt[i]) ++i;
}
// now restrict to here
// need to test ~1e4 candidates
for(ll c=i*i;;c++) {
bool gd=0;
auto check = [&](ll i, ll j) {
i = sqrtl(i+0.5L), j =sqrtl(j+0.5L);
if(binary_search(all(a),i) and binary_search(all(b),j)) gd=1;
};
for(ll j=1;j*j<=c;++j) {
if(c%j==0) {
check(j,c/j);
check(c/j,j);
}
}
if(!gd) {
cout << c << '\n';
break;
}
}
}