QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#719483 | #9426. Relearn through Review | Layn# | TL | 1069ms | 8124kb | C++14 | 969b | 2024-11-07 01:45:07 | 2024-11-07 01:45:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+10;
int T,n;
long long k,a[N],b[N],pre[N],suf[N];
long long gcd(long long x,long long y) {
if(!x||!y)return x|y;
return gcd(y,x%y);
}
int main() {
scanf("%d",&T);
while(T--) {
scanf("%d%lld",&n,&k);
int cnt=0;
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
for(int i=1;i<=n;i++)if(i==1||a[i]%a[i-1]!=0)b[++cnt]=a[i];
for(int i=1;i<=cnt;i++)pre[i]=gcd(b[i],pre[i-1]);
suf[cnt+1]=0;
for(int i=cnt;i>=1;i--)suf[i]=gcd(b[i],suf[i+1]);
long long ans=pre[cnt];
for(int i=1;i<=cnt;i++) {
long long cur=0;
for(int j=i;j<=cnt;j++) {
cur=gcd(b[j]+k,cur);
ans=max(ans,gcd(gcd(pre[i-1],suf[j+1]),cur));
//if(i==2)printf("%d %lld\n",j,cur);
if(cur<=1)break;
}
}
printf("%lld\n",ans);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7892kb
input:
2 6 2 5 3 13 8 10 555 3 0 3 6 9
output:
5 3
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 112ms
memory: 7972kb
input:
100000 1 608611451460421713 33155506392034032 1 743116173559300609 6138108577573005 7 364454564010802125 657035115675878115 657035115675878115 657035115675878115 657035115675878115 657035115675878115 292580551665075990 657035115675878115 4 316648374341335221 365788422120542814 182894211060271407 731...
output:
641766957852455745 749254282136873614 657035115675878115 182894211060271407 880411769063535667 560553564512176618 183698346865682381 962990836390050009 616597869896951268 878097339332572161 188820994675344528 997057718507559252 949074379610491450 37337367838628559 632093288650732211 3771217139073309...
result:
ok 100000 lines
Test #3:
score: 0
Accepted
time: 131ms
memory: 7880kb
input:
1000 71 451750502977198411 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 7015137...
output:
701513700102652904 628264251002959880 866034990978685601 718723820869997225 525309136656747615 453291245761058554 420366973911241294 500173849665919725 16701821680586640 794711320668492112 799961738480944637 963500289005941882 190368877908873112 973069943210898565 629019279628092667 1921616220783983...
result:
ok 1000 lines
Test #4:
score: 0
Accepted
time: 1069ms
memory: 8124kb
input:
100 5516 16561406822518327 121909691713696369 226403713182578971 940446193219943418 505054437099599243 505054437099599243 383144745385902874 470223096609971709 714042480037364447 417976085875530408 783705161016619515 888199182485502117 208988042937765204 330897734651461573 818536501506247049 7488738...
output:
17415670244813767 678667366385241526 375190657607916623 343566816881610443 293858497297593293 545063989451911922 101584687520632945 923261939978554511 245471164671296626 996567332718295422 871411820593738277 999473841903341933 575286590792404442 298698210937205101 265822932252018295 4113318308187297...
result:
ok 100 lines
Test #5:
score: -100
Time Limit Exceeded
input:
10 2651 1901143105096273 954803577560210292 636535718373473528 159133929593368382 159133929593368382 954803577560210292 477401788780105146 636535718373473528 636535718373473528 954803577560210292 636535718373473528 318267859186736764 636535718373473528 636535718373473528 318267859186736764 795669647...