#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() ((rand() << 14)+rand())
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846
ll gcd(ll x, ll y){return y==0?x:gcd(y, x%y);}
vector<ll> f;
ll d;
ll n, a[250005], k, g, c, p=0, weight[20]={1}, cnt[20];
set<ll> s;
bool dp[10000000];
void factor(ll X){
for (ll l=2; l*l<=X; ++l){
if (X%l==0){
f.pb(l);
c=0;
while(X%l==0){
X/=l;
c++;
}
cnt[p]=c;
weight[p+1]=weight[p]*(c+1);
++p;
}
}
if (X>1){
cnt[p]=1;
weight[p+1]=weight[p]*2;
++p;
f.pb(X);
}
}
bool check(ll G){
if (g/G<n*20){
for(ll l=G; l<g; l+=G) if (s.count(l)) return 0;
return 1;
}
fox(l, n){
if ((a[l]%g)%G==0) return 0;
}
return 1;
}
ll common(ll X){
ll t=0;
fox(l, p){
c=0;
while(X%f[l]==0){
X/=f[l];
c++;
}
t+=min(c, cnt[l])*weight[l];
}
return t;
}
ll val(ll X){
ll t=1;
fox(l, p){
c=X/weight[l]%(cnt[l]+1);
fox(l2, c) t*=f[l];
}
return t;
}
int main(){
scanf("%lli%lli", &d, &n);
--n; fox(l, n) scan(a[l]);
scanf("%lli", &k);
g=gcd(k, d);
factor(g);
fox(l, n){
a[l]%=g;
dp[common(a[l])]=1;
//cout << common(a[l]) << endl;
}
//return 0;
//cout << k << ' ' << d << ' ' << g << endl;
ll ans=0;
foxr(l, weight[p]){
//cout << l << ' ' << dp[l] << ' ' << val(l)<< endl;
if (dp[l]==0){
ans=max(ans, d/val(l));
continue;
}
fox(l2, p){
if (l/weight[l2]%(cnt[l2]+1)>0){
dp[l-weight[l2]]=1;
}
}
}
cout << ans;
return 0;
}
Compilation message
sej.cpp: In function 'int main()':
sej.cpp:89:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lli%lli", &d, &n);
~~~~~^~~~~~~~~~~~~~~~~~~~
sej.cpp:91:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lli", &k);
~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
464 KB |
Output is correct |
3 |
Correct |
2 ms |
524 KB |
Output is correct |
4 |
Correct |
2 ms |
524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
672 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
3 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
724 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
17 ms |
724 KB |
Output is correct |
4 |
Correct |
4 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
724 KB |
Output is correct |
2 |
Correct |
3 ms |
724 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
8 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
724 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
144 ms |
764 KB |
Output is correct |
4 |
Correct |
7 ms |
764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
764 KB |
Output is correct |
2 |
Correct |
2 ms |
764 KB |
Output is correct |
3 |
Correct |
2 ms |
764 KB |
Output is correct |
4 |
Correct |
9 ms |
764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
764 KB |
Output is correct |
2 |
Correct |
2 ms |
764 KB |
Output is correct |
3 |
Correct |
2 ms |
764 KB |
Output is correct |
4 |
Correct |
9 ms |
764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
764 KB |
Output is correct |
2 |
Correct |
2 ms |
764 KB |
Output is correct |
3 |
Correct |
115 ms |
764 KB |
Output is correct |
4 |
Correct |
10 ms |
764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
1404 KB |
Output is correct |
2 |
Correct |
35 ms |
1404 KB |
Output is correct |
3 |
Correct |
40 ms |
1404 KB |
Output is correct |
4 |
Correct |
73 ms |
3452 KB |
Output is correct |
5 |
Correct |
40 ms |
4096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
4884 KB |
Output is correct |
2 |
Correct |
127 ms |
4916 KB |
Output is correct |
3 |
Correct |
60 ms |
4916 KB |
Output is correct |
4 |
Correct |
62 ms |
6152 KB |
Output is correct |
5 |
Correct |
66 ms |
8628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
9012 KB |
Output is correct |
2 |
Correct |
162 ms |
9156 KB |
Output is correct |
3 |
Correct |
77 ms |
9156 KB |
Output is correct |
4 |
Correct |
85 ms |
11700 KB |
Output is correct |
5 |
Correct |
81 ms |
14188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
14236 KB |
Output is correct |
2 |
Correct |
162 ms |
14236 KB |
Output is correct |
3 |
Correct |
92 ms |
14260 KB |
Output is correct |
4 |
Correct |
84 ms |
16796 KB |
Output is correct |
5 |
Correct |
94 ms |
19428 KB |
Output is correct |