QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#625839 | #9426. Relearn through Review | WaO_o | WA | 1ms | 5668kb | C++20 | 2.0kb | 2024-10-09 21:21:49 | 2024-10-09 21:21:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define deg( x ) cerr<<""#x"="<<x<<endl
//#define endl '\n'
const int N=6e5+10;
int idn=0;
int fan[ N ];
int A[ N ];
int gcd( int a , int b ){
if( b==0 ) return a;
return gcd( b , a%b );
}
void solve(){
int n,k;
cin>>n>>k;
for( int i=1; i<=n; i++ ){
cin>>A[ i ];
}
int ans=0;
set<int> se;
se.insert( 0 );
for( int i=1; i<=n; i++ ){
int idx=0;
for( auto x:se ){
fan[ ++idx ]=gcd( x , A[ i ]+k );
fan[ ++idx ]=gcd( x , A[ i ] );
}
for( int e=1; e<=idx; e++ ) se.insert( fan[ e ] );
}
idn=0;
for( auto x:se ){
fan[ ++idn ]=x;
}
for( int i=idn; i>=1; i-- ){
int now=fan[ i ];
if( now <= ans ) break;
if( now==0 ) continue;
bool ok=false;
int l=1;
for( ; l<=n; l++ ){
if( A[ l ]%now != 0 ) break;
else{
if( ( A[ l ]+k )%now == 0 ) break;
else{
ok=true;
break;
}
}
}
if( ok ) continue;
int r=n;
for( ; r>=1; r-- ){
if( A[ r ]%now != 0 ) break;
else{
if( ( A[ r ]+k )%now==0 ) break;
else{
ok=true;
break;
}
}
}
if( ok ) continue;
for( int e=l; e<=r; e++ ){
if( ( A[ e ]+k )%now!=0 ){
ok=true;
break;
}
}
if( ok ) continue;
ans=max( ans , now );
}
cout<<ans<<endl;
}
signed main() {
ios::sync_with_stdio( 0 );
cin.tie( 0 ); cout.tie( 0 );
int T=1;
cin>>T;
while( T-- ){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5668kb
input:
2 6 2 5 3 13 8 10 555 3 0 3 6 9
output:
1 3
result:
wrong answer 1st lines differ - expected: '5', found: '1'