QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#736843 | #9705. Multiply | 15owzLy1 | WA | 21ms | 3896kb | C++20 | 1.9kb | 2024-11-12 13:39:03 | 2024-11-12 13:39:05 |
Judging History
answer
// 13:25
#include <bits/stdc++.h>
typedef long long ll;
const int N = 1e5 + 5;
int n;
ll x, y;
ll a[N];
ll p[505], c[505], pcnt;
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
void init() {
pcnt = 0;
ll t = x;
for (int i = 2; i <= 1e6; ++i) {
if (t % i == 0) {
c[++pcnt] = 0;
p[pcnt] = i;
while (t % i == 0) {
++c[pcnt];
t /= i;
}
}
}
if (t != 1) {
bool flag = false;
for (int i = 1; i <= n; ++i) {
ll g = gcd(a[i], t);
if (g != 1 && g != t) {
ll r = g, s = t / g;
flag = true;
if (s == r) {
c[++pcnt] = 2;
p[pcnt] = s;
} else {
c[++pcnt] = 1;
p[pcnt] = s;
c[++pcnt] = 1;
p[pcnt] = r;
}
break;
}
}
if (flag) {
c[++pcnt] = 1;
p[pcnt] = t;
}
}
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%d%lld%lld", &n, &x, &y);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &a[i]);
}
init();
ll ans = 1e18;
for (int i = 1; i <= pcnt; ++i) {
ll tot = 0, t = y;
while (t / p[i]) {
tot += t / p[i];
t /= p[i];
}
for (int j = 1; j <= n; ++j) {
t = a[j];
while (t / p[i]) {
tot -= t / p[i];
t /= p[i];
}
}
ans = std::min(ans, tot / c[i]);
}
printf("%lld\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 3896kb
input:
2 3 10 10 2 3 4 2 2 10 1 1
output:
2 8
result:
ok 2 number(s): "2 8"
Test #2:
score: -100
Wrong Answer
time: 21ms
memory: 3780kb
input:
8 929 98210021061137 164832982985885580 43576998167336 157303878397705 212661169553039 169068044677212 17733912750082 101059786177542 56528418806042 170741049344189 128297164019222 208810463591190 96264177952672 70816863413347 116985928070432 56330014332760 10006522486360 110959002803542 15298525649...
output:
1000000000000000000 1000000000000000000 1761303730724 3810060773695 8961243000749 8657430203778550 2603387692898890 569502267311933
result:
wrong answer 1st numbers differ - expected: '1059', found: '1000000000000000000'