bug求调
查看原帖
bug求调
168596
ProjectCF楼主2023/9/3 12:16
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stdlib.h>
#include <time.h>
#include <map>
#include <complex>
#include <math.h>
#include <stack>
#include <unordered_map>
#include <set>
using namespace std;
#define int long long
#define P 998244353
int qp(int a, int b) {
	int ans = 1;
	while (b) {
		if (b % 2)ans = ans * a % P;
		a = a * a % P;
		b /= 2;
	}
	return ans;
}
int fA(int i) {
	int ans = 0;
	while (i) {
		if (i % 2)ans++;
		i /= 2;
	}
	return ans;
}
int fB(int i) {
	int ans = 0;
	while (i) {
		if (i % 3)ans += i % 3;
		i /= 3;
	}
	return ans;
}
const int c1 = 21, c2 = 13, B1 = (1 << 21), B2 = (27 * 27 * 27 * 27 * 3);
int g[B1 * 2], f1[B1 * 2], f2[B1 * 2];
int* f = f1, * tp = f2;
int yp[110], zp[110], bp[10000010], xb, bm = 0;
int pb(int k) {
	for (int i = bm + 1; i <= k; i++)bp[i] = bp[i - 1] * xb % P;
	bm = max(bm, k);
	return bp[k];
}
signed main() {
	int n, x, y, z;
	cin >> n >> x >> y >> z;
	int ans = 0;
	{
		int r = qp(x, n / B1 * B1);
		yp[0] = zp[0] = 1;
		for (int i = 1; i <= 100; i++)yp[i] = yp[i - 1] * y % P, zp[i] = zp[i - 1] * z % P;
		for (int i = n / B1 * B1; i <= n; i++)ans = (ans + r * yp[fA(i)] % P * zp[fB(i)] % P) % P, r = r * x % P;
	}
	//cout << "A" << endl;
	xb = qp(x, B2);
	bp[0] = 1;
	for (int i = 0; i < n / B1; i++) {
		int r = B1 * (i - 1) / B2 - 1;
		while (B2 * r - B1 * i + B2 <= 0)r++;
		for (; B2 * r - B1 * i < B1; r++)g[B2 * r - B1 * i + B2] = (g[B2 * r - B1 * i + B2] + yp[fA(i)] * pb(r) % P * zp[fB(r)] % P) % P;
	}
	//cout << "B" << endl;
	int d1 = 1, d2 = 1;
	f[B2] = 1;
	while (d1 < B1 || d2 < B2) {
		if (d1 <= d2) {
			for (int i = -d2 + 1; i <= 2 * d1 - 1; i++)tp[i + B2] = (f[i + B2] + y * f[i - d1 + B2] % P) % P;
			int* pt = f;
			f = tp; tp = pt;
			d1 *= 2;
		}
		else {
			int tr = qp(x, d2) * z % P;
			for (int i = -3 * d2 + 1; i <= d1 - 1; i++)tp[i + B2] = (f[i + B2] + tr * f[i + d2 + B2] % P + tr * tr % P * f[i + d2 * 2 + B2] % P) % P;
			int* pt = f;
			f = tp; tp = pt;
			d2 *= 3;
		}
	}
	//cout << "C" << endl;
	for (int i = -B2 + 1; i <= B1 - 1; i++)ans = (ans + f[i + B2] * g[i + B2] % P) % P;
	cout << (ans + P - 1) % P << endl;
	return 0;
}

没找到bug 1238910AC 别的WA

2023/9/3 12:16
加载中...