This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, m, ans=1e18, p[12], n2;
int k, ps;
set<ll> v;
void dfs(ll u, bool ua=0) {
if(ua)
ans=min(u, ans);
v.insert(u);
for(int i=0; i<ps; ++i)
if(u%p[i]==0&&v.find(u/p[i])==v.end())
dfs(u/p[i], ua);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
n2=n;
for(ll i=2; i*i<n; ++i) {
if(n%i)
continue;
p[ps++]=i;
while(n%i==0)
n/=i;
}
if(n>0)
p[ps++]=n;
for(int i=0; i<k; ++i)
cin >> m, dfs(__gcd(m, n2), i==k-1);
cout << n2/ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |