QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#735925#9705. Multiplyrose_DKY#WA 1ms5680kbC++202.6kb2024-11-11 22:46:142024-11-11 22:46:15

Judging History

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

  • [2024-11-11 22:46:15]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5680kb
  • [2024-11-11 22:46:14]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define MAXN 200005
#define i64 ll
#define __int128 ll
i64 mul(i64 a, i64 b, i64 m) {
	return static_cast<__int128>(a) * b % m;
}
i64 power(i64 a, i64 b, i64 m) {
	i64 res = 1 % m;
	for (; b; b >>= 1, a = mul(a, a, m))
		if (b & 1)
			res = mul(res, a, m);
	return res;
}
bool isprime(i64 n) {
	if (n < 2)
		return false;
	static constexpr int A[] = {2, 3, 5, 7, 11, 13, 17, 19, 23};
	int s = __builtin_ctzll(n - 1);
	i64 d = (n - 1) >> s;
	for (auto a : A) {
		if (a == n)
			return true;
		i64 x = power(a, d, n);
		if (x == 1 || x == n - 1)
			continue;
		bool ok = false;
		for (int i = 0; i < s - 1; ++i) {
			x = mul(x, x, n);
			if (x == n - 1) {
				ok = true;
				break;
			}
		}
		if (!ok)
			return false;
	}
	return true;
}
vector<i64> factorize(i64 n) {
	vector<i64> p;
	function<void(i64)> f = [&](i64 n) {
		if (n <= 10000) {
			for (int i = 2; i * i <= n; ++i)
				for (; n % i == 0; n /= i)
					p.push_back(i);
			if (n > 1)
				p.push_back(n);
			return;
		}
		if (isprime(n)) {
			p.push_back(n);
			return;
		}
		auto g = [&](i64 x) {
			return (mul(x, x, n) + 1) % n;
		};
		i64 x0 = 2;
		while (true) {
			i64 x = x0;
			i64 y = x0;
			i64 d = 1;
			i64 power = 1, lam = 0;
			i64 v = 1;
			while (d == 1) {
				y = g(y);
				++lam;
				v = mul(v, abs(x - y), n);
				if (lam % 127 == 0) {
					d = __gcd(v, n);
					v = 1;
				}
				if (power == lam) {
					x = y;
					power *= 2;
					lam = 0;
					d = __gcd(v, n);
					v = 1;
				}
			}
			if (d != n) {
				f(d);
				f(n / d);
				return;
			}
			++x0;
		}
	};
	f(n);
	sort(p.begin(), p.end());
	return p;
}

ll a[MAXN];
ll c[MAXN];
void solve()
{
	ll n, x, y;
	cin >> n >> x >> y;
	
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	
	vector<ll> p = factorize(x);
	p.erase(unique(p.begin(), p.end()), p.end());
	for (int i = 0; i < p.size(); i++) {
		ll t = x, s = 0;
		while (t % p[i] == 0) {
			t /= p[i];
			s++;
		} 
		c[i] = s; 
	}
	
	ll res = 1e18;
	for (int i = 0; i < p.size(); i++) {
		ll pp = p[i], cc = c[i];
		ll c1 = 0, c2 = 0;
		for (int j = 1; j <= n; j++) {
			ll t = a[i];
			while (t) {
				c1 += t / pp;
				t /= pp;
			}
		}
		
		ll t = y;
		while (t) {
			c2 += t / pp;
			t /= pp;
		}
		
		res = min(res, (c2 - c1) / cc);
	}
	
	cout << res << endl;

}
int main()
{
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
	
	return 0;
}
/*
2
3 10 10
2 3 4
2 2 10
1 1
 */

详细

Test #1:

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

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: 1ms
memory: 5680kb

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
1000000000000000000
1000000000000000000
1000000000000000000
114308698200543721
-2072361686117539
132374215653233731

result:

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