QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#748794#9705. MultiplyHUY1Compile Error//C++202.5kb2024-11-14 21:28:202024-11-14 21:28:21

Judging History

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

  • [2024-11-14 21:28:21]
  • 评测
  • [2024-11-14 21:28:20]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define int ll
#define MAXN 200005
int mul(ll a, ll b, int m) {
	int r = a * b - m * (int)(1.L / m * a * b);
	return r - m * (r >= m) + m * (r < 0);
}
int mypow(int a, int b, int m) {
	int res = 1 % m;
	for (; b; b >>= 1, a = mul(a, a, m)) {
		if (b & 1) {
			res = mul(res, a, m);
		}
	}
	return res;
}
int B[] = {2, 3, 5, 7, 11, 13, 17, 19, 23};
bool MR(int n) {
	if (n <= 1) return 0;
	for (int p : B) {
		if (n == p) return 1;
		if (n % p == 0) return 0;
	}
	int m = (n - 1) >> __builtin_ctz(n - 1);
	for (int p : B) {
		int t = m, a = mypow(p, m, n);
		while (t != n - 1 && a != 1 && a != n - 1) {
			a = mul(a, a, n);
			t *= 2;
		}
		if (a != n - 1 && t % 2 == 0) return 0;
	}
	return 1;
}
int PR(ll n) {
	for (int p : B) {
		if (n % p == 0) return p;
	}
	auto f = [&](int x) -> int {
		x = mul(x, x, n) + 1;
		return x >= n ? x - n : x;
	};
	int x = 0, y = 0, tot = 0, p = 1, q, g;
	for (int i = 0; (i & 255) || (g = __gcd(p, n)) == 1; i++, x = f(x), y = f(f(y))) {
		if (x == y) {
			x = tot++;
			y = f(x);
		}
		q = mul(p, abs(x - y), n);
		if (q) p = q;
	}

	return g;
}
vector<int> fac(ll n) {
#define pb emplace_back
	if (n == 1) return {};
	if (MR(n)) return {n};
	int d = PR(n);
	auto v1 = fac(d), v2 = fac(n / d);
	auto i1 = v1.begin(), i2 = v2.begin();
	vector<int> ans;
	while (i1 != v1.end() || i2 != v2.end()) {
		if (i1 == v1.end()) {
			ans.pb(*i2++);
		} else if (i2 == v2.end()) {
			ans.pb(*i1++);
		} else {
			if (*i1 < *i2) {
				ans.pb(*i1++);
			} else {
				ans.pb(*i2++);
			}
		}
	}
	return ans;
}

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];
	}
	
	ll t = x;
	auto p = fac(x);
	
	for (int i = 0; i < p.size(); i++) {
		ll t = x, cnt = 0; 
		while (t % p[i] == 0) {
			cnt++;
			t /= p[i];
		}
		c[i] = cnt;
	}
	
	
	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[j];
			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
 */

詳細信息

answer.code:4:13: error: ‘::main’ must return ‘int’
    4 | #define int ll
      |             ^~
answer.code:130:1: note: in expansion of macro ‘int’
  130 | int main()
      | ^~~