QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#710620 | #9426. Relearn through Review | quannguyen2009 | WA | 123ms | 5704kb | C++23 | 1.1kb | 2024-11-04 20:44:48 | 2024-11-04 20:44:49 |
Judging History
answer
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define gcd __gcd
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
using namespace std;
const int N=3e5+5, mod = 1e9+7, inf = 1e18;
int n, k;
int a[N], suf[N];
void solve() {
cin >> n >> k;
for (int i=1; i<=n; i++) cin >> a[i];
suf[n+1] = 0;
for (int i=n; i>=1; i--) suf[i] = gcd(suf[i+1], a[i]);
int ans = suf[1];
int tmp = 0;
for (int i=1; i<=n; i++) {
if(gcd(tmp, a[i])!=tmp) {
int res = 0;
for (int j=i+1; j<=n; j++) {
res = gcd(res, a[j]+k);
ans = max(ans, gcd(gcd(gcd(tmp, a[i]), res), suf[j+1]));
}
}
tmp = gcd(tmp, a[i]);
}
cout << ans << '\n';
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t; cin >> t;
while(t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5636kb
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: 123ms
memory: 5704kb
input:
100000 1 608611451460421713 33155506392034032 1 743116173559300609 6138108577573005 7 364454564010802125 657035115675878115 657035115675878115 657035115675878115 657035115675878115 657035115675878115 292580551665075990 657035115675878115 4 316648374341335221 365788422120542814 182894211060271407 731...
output:
33155506392034032 6138108577573005 15 3 880411769063535667 98423435849394582 1 962990836390050009 484915690810412536 878097339332572161 149180825015886938 361813583202892479 915781395066183375 37337367838628559 1 1 2 494408344393555851 1 414849785128019057 118387461231999184 1 1 963758727749334806 1...
result:
wrong answer 1st lines differ - expected: '641766957852455745', found: '33155506392034032'