QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#721850#9705. Multiplytarjen#WA 0ms3904kbC++202.8kb2024-11-07 17:00:332024-11-07 17:00:34

Judging History

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

  • [2024-11-07 17:00:34]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3904kb
  • [2024-11-07 17:00:33]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll, bool>P;
mt19937_64 rnd(time(0));
namespace Pollard_Rho
{
#define ldb long double
ll mul(ll x, ll y, ll mod)
{
	return ((x * y - (ll)((ldb)x / mod * y) * mod) + mod) % mod;
}
ll gcd(ll a, ll b)
{
	return (b == 0 ? a : gcd(b, a % b));
}
ll ksm(ll a, ll b, ll mod)
{
	ll ans = 1; a %= mod;
	while (b) {if (b & 1)ans = mul(ans, a, mod); b >>= 1; a = mul(a, a, mod);}
	return ans;
}
int pr[19] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,41,43,47,53,59,61,67};
bool Miller_Rabin(ll n)
{
	if (n == 2 || n == 3)return 1;
	if (n % 2 == 0 || n == 1)return 0;
	ll d = n - 1;
	int s = 0;
	while (d % 2 == 0)s ++, d >>= 1;
	for (int i = 0; i <= 18; i ++)
	{
		if (pr[i] >= n)break;
		ll a = pr[i];
		ll x = ksm(a, d, n);
		ll y = 0;
		for (int j = 0; j <= s - 1; j ++)
		{
			y = mul(x, x, n);
			if (y == 1 && x != 1 && x != (n - 1))return 0;
			x = y;
		}
		if (y != 1)return 0;
	}
	return 1;
}
ll Pollard_Rho(ll n)
{
	ll now, pre, g;
	while (true)
	{
		now = pre = rnd() % (n - 1) + 1;
		g = 1;
		ll c = rnd() % (n - 1) + 1;
		for (int i = 1, fst = 1 ;; i ++)
		{
			now = (mul(now, now, n) + c) % n;
			g = mul(g, abs(now - pre), n);
			if (now == pre || !g)break;
			if (i == fst)
			{
				g = gcd(g, n);
				if (g > 1)return g;
				if (i == fst)pre = now, fst <<= 1;
			}
		}
	}
}
void Find(ll n)
{
	if (n == 1)return ;
	if (Miller_Rabin(n))
	{
		P[n] = 1;
		return ;
	}
	ll p = Pollard_Rho(n);
	if(n%p!=0)return;
    int c = 0;
	while (!(n % p))
	{
		n /= p, c ++;
	}
    Find(p);
	Find(n);
}
}
void getp(ll x,set<ll> &s){
    Pollard_Rho :: Find(x);
    for (auto [x, _] : P)s.insert(x);
    P.clear();
}
ll solve()
{
    ll n,X,Y;cin>>n>>X>>Y;
    ll ans=6e18;
    vector<ll>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    auto cal = [&](ll x,ll y){// cal x! y
        ll ans=0;
        while(x>0){
            // cout<<"x="<<x<<" y="<<y<<endl;
            ans+=x/y;x/=y;
        }
        return ans;
    };
    auto calans = [&](int x){
        if(x==1)return (ll)6e18;
        ll sum=0;
        for(auto &it:a)sum+=cal(it,x);
        ll ysum=cal(Y,x);
        // cout<<"x="<<x<<" sum="<<sum<<" ysum="<<ysum<<endl;
        ll t=0;
        {
            ll G=X;
            while(G%x==0)t++,G/=x;
        }
        if(t==0)return (ll)6e18;
        return (ysum-sum)/t;
    };
    set<ll>s;
    getp(X,s);
    // for(auto it:s)cout<<it<<" ";;cout<<endl;
    ll Z=X;
    for(auto it:s){
        while(Z%it==0)Z/=it;
    }
    for(auto it:s){ans=min(ans,calans(it));}
    if(Z>1)ans=min(ans,calans(Z));
    return ans;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;cin>>T;while(T--)cout<<solve()<<"\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3904kb

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: 0ms
memory: 3692kb

input:

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

output:

6000000000000000000
95837140
1761303730724
3810060773695
8961243000749
8657430203778550
2603387692898890
569502267311933

result:

wrong answer 1st numbers differ - expected: '1059', found: '6000000000000000000'