QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#736934 | #9705. Multiply | 15owzLy1 | AC ✓ | 118ms | 4588kb | C++20 | 2.8kb | 2024-11-12 14:00:13 | 2024-11-12 14:00:14 |
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);
}
struct Pollard_Rho
{
ll md(ll x, ll p){while(x>p)x-=p;return x;}
ll mult(ll a, ll b, ll p)
{
ll ans=0, t=a;
for(;b;b>>=1,t=md(t+t,p))if(b&1)ans=md(ans+t,p);
return ans;
}
ll pow(ll a, ll b, ll p)
{
ll ans=1, t=a;
for(;b;b>>=1,t=mult(t,t,p))if(b&1)ans=mult(ans,t,p);
return ans;
}
bool MR(ll n)
{
ll a, t, u, i, x, y, tim=20;
if(n==2)return true;
if(~n&1)return false;
if(n==3 or n==5)return true;
if(n%3==0 or n%5==0)return false;
for(t=0,u=n-1;~u&1;u>>=1,t++);
while(tim--)
{
a=rand()%(n-1)+1;
for(y=x=pow(a,u,n),i=1;i<=t;i++)
{
x=mult(x,x,n);
if(x==1 and y!=n-1 and y!=1)return false;
y=x;
}
if(x!=1)return false;
}
return true;
}
ll pollard_rho(ll n, ll c)
{
ll i, k, x=rand()%n, y=x, d;
for(i=1,k=2;;i++)
{
x=(mult(x,x,n)+c)%n;
d=gcd(y>x?y-x:x-y,n);
if(d>1 and d<n)return d;
if(x==y)return n;
if(i==k)y=x,k<<=1;
}
}
void find(ll n, ll c, std::map<ll,ll>& ans)
{
if(n==1)return;
if(MR(n)){ans[n]++;return;}
ll p=pollard_rho(n,c);
for(;p==n;c++)p=pollard_rho(n,c);
find(p,c,ans), find(n/p,c,ans);
}
std::map<ll,ll> run(ll n)
{
std::map<ll,ll> ans;
find(n,1,ans);
return ans;
}
};
void init() {
pcnt = 0;
Pollard_Rho pr;
auto mp = pr.run(x);
for (auto [pri, cnt] : mp) {
p[++pcnt] = pri;
c[pcnt] = cnt;
}
}
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: 0ms
memory: 3756kb
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: 0
Accepted
time: 5ms
memory: 4056kb
input:
8 929 98210021061137 164832982985885580 43576998167336 157303878397705 212661169553039 169068044677212 17733912750082 101059786177542 56528418806042 170741049344189 128297164019222 208810463591190 96264177952672 70816863413347 116985928070432 56330014332760 10006522486360 110959002803542 15298525649...
output:
1059 95837140 1761303730724 3810060773695 8961243000749 8657430203778550 2603387692898890 569502267311933
result:
ok 8 numbers
Test #3:
score: 0
Accepted
time: 116ms
memory: 4520kb
input:
8 92894 80454414905270281 520643152573491735 2064229122797 4223622787947 1054260245418 4094316313084 3929142530824 6452342289094 3762455615113 3157146960681 5603173442583 1875814573143 1801348242678 2409547278342 6854531398370 1240913563145 1848446319539 1493011800303 5389461335879 7286083232997 579...
output:
6 114168802 81596535601 11028882122096 100316204821427 4718268084920428 394167331265621 539500856199383
result:
ok 8 numbers
Test #4:
score: 0
Accepted
time: 118ms
memory: 4588kb
input:
8 92894 8280090210874177 543856067505017676 7628166265475 4448095856140 3732480525951 6624251584927 2217648228673 2129611741353 2848644172912 8103647146535 1467047865398 2185292600211 1765086497170 6371594269098 8613841584311 6848101874651 718312212561 4093427071182 2289683844966 6915866934586 51966...
output:
65 1246786758 333319010645 13129729242598 84397513456572 1419008292818811 145866895461700 594315405335288
result:
ok 8 numbers
Test #5:
score: 0
Accepted
time: 94ms
memory: 4568kb
input:
8 92894 98210021061137 164832982985885580 437808801937 1580398501813 2136561393792 1698590570197 178168838012 1015326106916 567928960914 1715398889850 1288974230710 2097874172186 967145654868 711481916793 1175332657008 565935634477 100533395596 1114781424652 1537010227806 201374141170 2002549530277 ...
output:
1678 15138363549 3851961323533 9546266194484 65456023237176 50284070499384881 2136489879131768 343921703953617
result:
ok 8 numbers
Test #6:
score: 0
Accepted
time: 23ms
memory: 3756kb
input:
8 929 904648320997198759 857077283552821319 576128640757999 1022489209332927 342306048548590 328717138574533 439703699384584 1250841949052893 226446805904869 337311781446902 272450687310201 983490180331727 1329593231427121 1057041717229744 110875391163525 631842700541257 353425137200360 106750162246...
output:
0 14963454 29504132475 203878226275 8778367031870 15079682243266455 149351201237842 2430883872230178
result:
ok 8 numbers
Test #7:
score: 0
Accepted
time: 100ms
memory: 4544kb
input:
8 92894 904648320997198759 857077283552821319 5796497585331 10287383430483 3443981158080 3307261546850 4423910306892 12584867031801 2278307777449 3393733253885 2741158205233 9895009642558 13377192887408 10635020251022 1115530268804 6357043250803 3555851608183 10740258578761 8070377462103 13134968899...
output:
0 21583598 4114016689 5953125168816 9610340743247 133189637386353298 124668826875053 21617048982826
result:
ok 8 numbers