#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<ll> primes;
ll ans = 1e18;
set<ll> illegalNumbers;
void handleNumber(ll n, bool updAns) {
illegalNumbers.insert(n);
if (updAns) ans = min(ans, n);
for (ll 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;
}
}
if (n>1) primes.pb(n);
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 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
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 |
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 |
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 |
Correct |
2 ms |
492 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 |
Correct |
10 ms |
364 KB |
Output is correct |
4 |
Correct |
7 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
17 ms |
1004 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
17 ms |
1132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
99 ms |
364 KB |
Output is correct |
4 |
Correct |
15 ms |
1004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
364 KB |
Output is correct |
2 |
Correct |
18 ms |
1132 KB |
Output is correct |
3 |
Correct |
70 ms |
364 KB |
Output is correct |
4 |
Correct |
17 ms |
1132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
11 ms |
364 KB |
Output is correct |
4 |
Correct |
18 ms |
1132 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 |
Correct |
69 ms |
364 KB |
Output is correct |
4 |
Correct |
18 ms |
1132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
1388 KB |
Output is correct |
2 |
Correct |
42 ms |
1388 KB |
Output is correct |
3 |
Correct |
58 ms |
1900 KB |
Output is correct |
4 |
Correct |
83 ms |
2708 KB |
Output is correct |
5 |
Correct |
53 ms |
2284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
1900 KB |
Output is correct |
2 |
Correct |
328 ms |
1900 KB |
Output is correct |
3 |
Correct |
72 ms |
1772 KB |
Output is correct |
4 |
Correct |
83 ms |
2796 KB |
Output is correct |
5 |
Correct |
81 ms |
3180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
2028 KB |
Output is correct |
2 |
Correct |
414 ms |
2000 KB |
Output is correct |
3 |
Correct |
98 ms |
1900 KB |
Output is correct |
4 |
Correct |
107 ms |
1900 KB |
Output is correct |
5 |
Correct |
95 ms |
1900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
1900 KB |
Output is correct |
2 |
Correct |
392 ms |
3692 KB |
Output is correct |
3 |
Correct |
111 ms |
3692 KB |
Output is correct |
4 |
Correct |
117 ms |
3820 KB |
Output is correct |
5 |
Correct |
103 ms |
3692 KB |
Output is correct |