QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#855980 | #9738. Make It Divisible | shi2uku# | WA | 0ms | 3596kb | C++14 | 1.2kb | 2025-01-13 14:13:54 | 2025-01-13 14:13:55 |
Judging History
answer
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a.begin(), a.end());
ll l = a[0] + 1, r = a[0] + k;
for (int i = 0; i < n; ++i) a[i] -= l - 1;
int d = 0;
for (int i = 1; i < n; ++i) d = __gcd(d, a[i]), d = __gcd(d, a[i] - a[i - 1]);
if (d == 0) {
int num = r - l + 1;
ll sum = 1ll * num * (r + l) / 2;
cout << num << " " << sum - 1ll * (l - 1) * num << '\n';
return;
}
set<int> s;
auto valid = [&](int x) -> bool {
return x >= l && x <= r;
};
for (int i = 1; 1ll * i * i <= d; ++i) {
if (d % i == 0) {
if (valid(i)) s.insert(i);
if (valid(d / i)) s.insert(d / i);
}
}
ll sum = 0;
for (auto u : s) sum += u;
int num = s.size();
cout << num << " " << sum - 1ll * (l - 1) * num << '\n';
}
int main() {
cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
int t;
cin >> t;
while (t--) solve();
}
/*
3
5 10
7 79 1 7 1
2 1000000000
1 2
1 100
1000000000
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3524kb
input:
3 5 10 7 79 1 7 1 2 1000000000 1 2 1 100 1000000000
output:
3 8 0 0 100 5050
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3596kb
input:
4 201 1000000000 1 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5...
output:
0 0 1 1 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '0 0', found: '1 1'