QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#776770 | #9738. Make It Divisible | RWeakest | RE | 21ms | 39764kb | C++20 | 3.3kb | 2024-11-23 20:54:25 | 2024-11-23 20:54:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
const int MXZ = 5e4 + 10;
i64 a[MXZ];
i64 prm[4000010], mp[4000010];
int idx = 0;
void euler_sieve(int n) {
for (int i = 2; i <= n; ++i) mp[i] = i;
for (int i = 2; i <= n; ++i) {
if (mp[i] == i) prm[++idx] = i;
for (int j = 1; j <= idx && prm[j] * i <= n; ++j) {
mp[i * prm[j]] = prm[j];
if (i % prm[j] == 0) break;
}
}
}
vector<pii> pv;
vector<i64> fas;
void dfs(int i,i64 val)
{
if (i == pv.size()) {
fas.emplace_back(val);
return;
}
i64 t = 1;
for (int j = 0; j <= pv[i].second; ++j)
{
dfs(i + 1,val * t);
t = t * pv[i].first;
}
}
int main(void) {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
euler_sieve(4e6);
int T;
cin >> T;
while (T--) {
i64 n, k;
cin >> n >> k;
if (n == 1) {
i64 a1;
cin >> a1;
cout << k << ' ' << ((1 + k) * k / 2) << '\n';
continue;
}
set<i64> S;
for (int i = 1; i <= n; ++i)
cin >> a[i], S.insert(a[i]);
i64 maxv = a[1], minv = a[1];
i64 mind = 1e9 + 3, minbi = 0;
for (int i = 2; i <= n; ++i) {
i64 u = a[i], v = a[i - 1];
minv = min(minv, u), maxv = max(maxv, u);
if (u > v) swap(u, v);
if (v - u < mind)
mind = v - u, minbi = u;
}
if (33 < S.size())
cout << "0 0\n";
else {
i64 cnt = 0, sum = 0;
set<pii> Sp;
for (int i = 2; i <= n; ++i) {
int u = a[i], v = a[i - 1];
if (u > v) swap(u, v);
else if (u == v) continue;
Sp.insert({u, v});
}
i64 v = mind, d = 1;
map<int, int> fac;
while (v >= 4e6) {
for (i64 i = 2; i * i <= v; ++i)
if (v % i) continue;
else {
v = v / i;
fac[i]++;
break;
}
}
while (v > 1) {
fac[mp[v]]++;
v = v / mp[v];
}
for (auto p: fac)
//cout << p.first << ' ' << p.second << '\n',
pv.emplace_back(p);
sort(pv.begin(),pv.end());
dfs(0,1);
bool suc = true;
for (auto d : fas)
{
if (d == mind) continue;
i64 x = mind / d - minbi;
if (x >= k) continue;
for (auto p : Sp)
{
auto s = p.first,t = p.second;
if ((t + x) % (s + x) == 0) continue;
else
{
suc = false;
break;
}
}
if (suc)
cnt++,sum += x;
}
cout << cnt << ' ' << sum << '\n';
}
pv.clear();
fas.clear();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 21ms
memory: 39764kb
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
Runtime Error
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...