跳到正文

剪贴板

剪贴板 d1uadszw

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 15;
constexpr int M = 1e5;
constexpr int mod = 998244353;
int n, A, B, a[1 << N], b[1 << N], inv[N + 1], ka, inva, kb, invb;
long long ans;
inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
int pw(int x, int y) {
	int ret = 1;
	for (; y; y >>= 1, x = 1ll * x * x % mod) if (y & 1) ret = 1ll * ret * x % mod;
	return ret;
}
struct SPS{
	int val[1 << N];
	SPS() { memset(val, 0, sizeof val); }
	SPS(const SPS &another) { memcpy(val, another.val, sizeof val); } 
	SPS &operator = (const SPS &another) { memcpy(val, another.val, sizeof val); return *this; }
	SPS operator + (const SPS &another) const {
		SPS ret;
		for (int S = 0; S < (1 << n); ++S) ret.val[S] = add(val[S], another.val[S]);
		return ret;
	}
	SPS operator * (const int &another) const {
		SPS ret;
		for (int S = 0; S < (1 << n); ++S) ret.val[S] = 1ll * val[S] * another % mod;
		return ret;
	}
	SPS operator * (const SPS &another) const {
		SPS ret;
		for (int S = 0; S < (1 << n); ++S) ret.val[S] = 1ll * val[S] * another.val[S] % mod;
		return ret;
	}
	void FMT(bool op) {
		for (int i = 1; i < (1 << n); i <<= 1) for (int j = 0; j < (1 << n); j += (i << 1)) for (int k = 0; k < i; ++k) {
			if (op == 0) val[i ^ j ^ k] = add(val[i ^ j ^ k], val[j ^ k]);
			if (op == 1) val[i ^ j ^ k] = add(val[i ^ j ^ k], mod - val[j ^ k]);
		}
	}
};
struct FPS{
	SPS val[N + 1];
	FPS() {; }
	FPS(const FPS &another) { for (int i = 0; i <= n; ++i) val[i] = another.val[i]; }
	FPS &operator = (const FPS &another) { for (int i = 0; i <= n; ++i) val[i] = another.val[i]; return *this; }
	FPS operator + (const FPS &another) const {
		FPS ret;
		for (int i = 0; i <= n; ++i) ret.val[i] = val[i] + another.val[i];
		return ret;
	}
	FPS operator * (const int &another) const {
		FPS ret;
		for (int i = 0; i <= n; ++i) ret.val[i] = val[i] * another;
		return ret;
	}
	FPS operator * (const FPS &another) const {
		FPS ret;
		for (int i = 0; i <= n; ++i) for (int j = 0; j <= i; ++j) ret.val[i] = ret.val[i] + val[j] * another.val[i - j];
		return ret;
	}
	void get(int *a) {
		for (int S = 0; S < (1 << n); ++S) val[__builtin_popcount(S)].val[S] = a[S];
		for (int i = 0; i <= n; ++i) val[i].FMT(0);
	}
	void set(int *a) {
		for (int i = 0; i <= n; ++i) val[i].FMT(1);
		for (int S = 0; S < (1 << n); ++S) a[S] = val[__builtin_popcount(S)].val[S];
	}
} f, g;
FPS ln(const FPS &f) {
	FPS g;
	for (int i = 1; i <= n; ++i) {
		SPS tmp;
		for (int j = 1; j < i; ++j) tmp = tmp + g.val[j] * f.val[i - j] * j;
		g.val[i] = f.val[i] + tmp * (mod - inv[i]); 
	}
	return g;
}
FPS exp(const FPS &g) {
	FPS f;
	for (int S = 0; S < (1 << n); ++S) f.val[0].val[S] = 1;
	for (int i = 1; i <= n; ++i) {
		SPS tmp;
		for (int j = 1; j <= i; ++j) tmp = tmp + g.val[j] * f.val[i - j] * j;
		f.val[i] = tmp * inv[i];
	}
	return f;
}
signed main() {
	cin.tie(0) -> sync_with_stdio(false);
	cin >> A >> B, A += 1e9, B += 1e9;
	n = 1, inv[1] = 1;
	for (int i = 2; i <= n; ++i) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
	// 低位 
	a[0] = A % M + 1, a[1] = B % M, b[0] = b[1] = 1;
	ka = a[0], inva = pw(ka, mod - 2);
	for (int S = 0; S < (1 << n); ++S) a[S] = 1ll * a[S] * inva % mod;
	kb = b[0], invb = pw(kb, mod - 2);
	for (int S = 0; S < (1 << n); ++S) b[S] = 1ll * b[S] * invb % mod;
	f.get(a), g.get(b);
	f = ln(f), g = ln(g), f = f + g, f = exp(f);
	f.set(a);
	for (int S = 0; S < (1 << n); ++S) a[S] = 1ll * a[S] * ka % mod * kb % mod;
	ans += add(a[(1 << n) - 1], mod - 1);
	// 高位
	a[0] = A / M + 1, a[1] = B / M, b[0] = b[1] = 1;
	ka = a[0], inva = pw(ka, mod - 2);
	for (int S = 0; S < (1 << n); ++S) a[S] = 1ll * a[S] * inva % mod;
	kb = b[0], invb = pw(kb, mod - 2);
	for (int S = 0; S < (1 << n); ++S) b[S] = 1ll * b[S] * invb % mod;
	f.get(a), g.get(b);
	f = ln(f), g = ln(g), f = f + g, f = exp(f);
	f.set(a);
	for (int S = 0; S < (1 << n); ++S) a[S] = 1ll * a[S] * ka % mod * kb % mod;
	ans += 1ll * add(a[(1 << n) - 1], mod - 1) * M;
	ans -= 2e9;
	cout << ans;
}