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 <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
long long ans;
long long total;
const long long MAXN = 250005;
long long arr[MAXN];
bool common(long long x){
for(long long i=1;i<=total;i++){
if(arr[i]%x == 0){
return false;
}
}
return true;
}
int main() {
long long n,k;
cin>>n>>k;
for(long long i=1;i<=k;i++){
cin>>arr[i];
}
for(long long i=1;i<=k;i++){
arr[i] = __gcd(n,arr[i]);
}
sort(arr+1,arr+k);
for(long long i=1;i<k;i++){
if(arr[i]!=arr[i-1]){
total++;
arr[total] = arr[i];
}
}
for(long long i=1;i<=sqrt(arr[k]);i++){
if(arr[k]%i == 0){
if(common(i)){
ans = n/i;
break;
}
if(common(arr[k]/i)){
ans = (n/arr[k]*i);
}
}
}
cout<<ans<<endl;
}
# | 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... |