QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#736855#9705. Multiply15owzLy1WA 25ms3920kbC++202.0kb2024-11-12 13:41:532024-11-12 13:41:53

Judging History

你现在查看的是最新测评结果

  • [2024-11-12 13:41:53]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:3920kb
  • [2024-11-12 13:41:53]
  • 提交

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);
        init();
        // printf("pcnt=%lld\n", pcnt);
        // for (int i = 1; i <= pcnt; ++i) {
        //     printf("%lld %lld\n", p[i], c[i]);
        // }
        for (int i = 1; i <= n; ++i) {
            scanf("%lld", &a[i]);
        }

        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;
}

详细

Test #1:

score: 100
Accepted
time: 6ms
memory: 3832kb

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: 25ms
memory: 3920kb

input:

8
929 98210021061137 164832982985885580
43576998167336 157303878397705 212661169553039 169068044677212 17733912750082 101059786177542 56528418806042 170741049344189 128297164019222 208810463591190 96264177952672 70816863413347 116985928070432 56330014332760 10006522486360 110959002803542 15298525649...

output:

1059
59
1761303730724
3810060773695
8961243000749
8657430203778550
2603387692898890
569502267311933

result:

wrong answer 2nd numbers differ - expected: '95837140', found: '59'