QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#768853 | #9705. Multiply | IllusionaryDominance# | WA | 2ms | 3804kb | C++20 | 3.9kb | 2024-11-21 14:52:38 | 2024-11-21 14:52:39 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
using u64 = unsigned long long;
namespace PR{
ll fac[1000000], cnt;
gp_hash_table <ll, bool> h;
ll times(const ll &a, const ll &b, const ll &p) {
ll res = a * b - (ll)((long double)a / p * b + 0.5) * p;
return res < 0 ? res + p : res;
}
ll power(ll a, ll n, ll p) {
ll ans = 1;
a %= p;
while (n) {
if (n & 1) ans = times(ans, a, p);
a = times(a, a, p); n >>= 1;
}
return ans;
}
ll gcd(ll a, ll b) {
while (b) {
ll t = b;
b = a % b;
a = t;
}
return a;
}
bool check(const ll &x) {
if (x < 2) return false;
for (int i = 2; i * i <= x; i ++)
if (x % i == 0) return false;
return true;
}
bool miller_rabin(const ll &n) {
if (n < 100) return check(n);
if (h.find(n) != h.end()) return h[n];
if ((~ n & 1) || n % 3 == 0 || n % 5 == 0 || n % 7 == 0 || n % 11 == 0 || n % 13 == 0 || n % 17 == 0 || n % 19 == 0 || n % 23 == 0 || n % 29 == 0) return false;
ll b = __builtin_ctzll(n - 1), x = (n - 1) >> b;
static int prime[12] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};
for (int i = 0; i < 12; i ++) {
ll cur = power(prime[i], x, n), nxt;
for (int j = 1; j <= b && cur != 1; j ++) {
nxt = times(cur, cur, n);
if (nxt == 1 && cur != n - 1) {
h[n] = 0;
return false;
}
cur = nxt;
}
if (cur != 1) {
h[n] = 0;
return false;
}
}
h[n] = 1;
return true;
}
ll add(const ll &a, const ll &b, const ll &p) {
u64 t = (u64)a + (u64)b;
t -= t < (u64)p ? 0 : p;
return t;
}
ll pollard_rho(const ll &n) {
ll c = (rand() << 15 | rand()) % n + 1, a1 = 0, a2;
a1 = add(times(a1, a1, n), c, n);
a2 = add(times(a1, a1, n), c, n);
while (a1 != a2) {
ll d = gcd(abs(a1 - a2), n);
if (d > 1) return d;
a1 = add(times(a1, a1, n), c, n);
a2 = add(times(a2, a2, n), c, n);
a2 = add(times(a2, a2, n), c, n);
}
return n;
}
void Do(ll n) {
if (n < 2) return ;
if (miller_rabin(n)) {
fac[++ cnt] = n;
return ;
}
ll s = sqrt(n);
if (s * s == n) {
Do(s); Do(s); return ;
}
s = pollard_rho(n);
while (s == 1 || s == n) s = pollard_rho(n);
Do(s); Do(n / s);
}
vector<int> solve(const ll &n) {
cnt = 0;
Do(n);
sort(fac + 1, fac + cnt + 1);
vector<int> re;
for (int i = 1; i <= cnt; ++ i) re.push_back(fac[i]);
return re;
}
};
void solve(){
int N;
long long X, Y;
cin >> N >> X >> Y;
vector<int>fac = PR::solve(X);
vector<long long> A(N + 1);
for (int i = 1; i <= N; ++ i) cin >> A[i];
long long ans = 1e18;
for (int i = 0; i < fac.size(); ++ i){
long long tot = 1;
while(i + 1 < fac.size() && fac[i] == fac[i + 1]) ++ i;
long long sumY = 0, sumA = 0;
for (__int128 now = fac[i]; now <= Y; now *= fac[i]){
sumY += Y / now;
for (int j = 1; j <= N; ++ j) sumA += A[j] / now;
}
ans = min(ans, (sumY - sumA) / tot);
}
cout << ans << "\n";
}
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T; cin >> T;
while(T --) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
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: 2ms
memory: 3804kb
input:
8 929 98210021061137 164832982985885580 43576998167336 157303878397705 212661169553039 169068044677212 17733912750082 101059786177542 56528418806042 170741049344189 128297164019222 208810463591190 96264177952672 70816863413347 116985928070432 56330014332760 10006522486360 110959002803542 15298525649...
output:
47873232 95837140 1761303730724 3810060773695 8961243000749 8657430203778550 10413550771595562 2278009069247734
result:
wrong answer 1st numbers differ - expected: '1059', found: '47873232'