QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#719474 | #9426. Relearn through Review | Layn# | WA | 80ms | 8048kb | C++14 | 959b | 2024-11-07 01:38:50 | 2024-11-07 01:38:52 |
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(a[i]!=a[i-1])b[++cnt]=a[i];
for(int i=1;i<=cnt;i++)pre[i]=gcd(b[i],pre[i-1]);
b[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: 8048kb
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: -100
Wrong Answer
time: 80ms
memory: 7912kb
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 1 98423435849394582 1 1 484915690810412536 3 149180825015886938 361813583202892479 915781395066183375 37337367838628559 1 1 2 494408344393555851 2 2 118387461231999184 1 383091938972089281 1 1 580787185875674097 3 4435168108...
result:
wrong answer 5th lines differ - expected: '880411769063535667', found: '1'