#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define inf 1000000010
vector<int> primes;
ll ans = 1e18;
set<ll> illegalNumbers;
void handleNumber(ll n, bool updAns) {
illegalNumbers.insert(n);
if (updAns) ans = min(ans, n);
for (int p : primes) {
if (n % p == 0 && illegalNumbers.count(n/p) == 0) {
handleNumber(n/p, updAns);
}
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
ll n; int k; cin >> n >> k;
ll origN = n;
if (k == 1) {
cout << n << endl;
return 0;
}
for (ll i = 2; i*i <= n; i++) {
if (n%i == 0) {
primes.pb(i);
while (n%i == 0) n /= i;
}
}
F0R(i, k) {
ll x; cin >> x;
handleNumber(__gcd(origN, x), i==k-1);
}
cout << origN/ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
2 ms |
492 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
10 ms |
364 KB |
Output is correct |
4 |
Correct |
5 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
15 ms |
1004 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
100 ms |
492 KB |
Output is correct |
4 |
Correct |
13 ms |
1004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
364 KB |
Output is correct |
2 |
Correct |
21 ms |
1280 KB |
Output is correct |
3 |
Correct |
69 ms |
376 KB |
Output is correct |
4 |
Incorrect |
14 ms |
1004 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
68 ms |
364 KB |
Output is correct |
4 |
Correct |
18 ms |
1004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
876 KB |
Output is correct |
2 |
Correct |
42 ms |
1516 KB |
Output is correct |
3 |
Incorrect |
53 ms |
2156 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
876 KB |
Output is correct |
2 |
Correct |
302 ms |
4076 KB |
Output is correct |
3 |
Incorrect |
71 ms |
2940 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
1004 KB |
Output is correct |
2 |
Correct |
372 ms |
4844 KB |
Output is correct |
3 |
Correct |
93 ms |
3564 KB |
Output is correct |
4 |
Correct |
105 ms |
3820 KB |
Output is correct |
5 |
Incorrect |
90 ms |
3564 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
876 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |