QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#338745#4056. 进制转换Link_Cut_Y#35 92ms236508kbC++201.6kb2024-02-26 10:48:092024-02-26 10:48:10

Judging History

This is the latest submission verdict.

  • [2024-02-26 10:48:10]
  • Judged
  • Verdict: 35
  • Time: 92ms
  • Memory: 236508kb
  • [2024-02-26 10:48:09]
  • Submitted

answer

#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#define int long long
#define vit vector<int>
#define rep(i, a, b) for (int i = (a); i <= (b); i ++ )
#define rop(i, a, b) for (int i = (a); i < (b); i ++ )
#define dep(i, a, b) for (int i = (a); i >= (b); i -- )

using namespace std;

const int N = 1e7 + 10;
const int mod = 998244353;
int px[N], py[150], pz[150], a[N], b[N];
int n, x, y, z, ans, f[150][2][150];
int cnt = 0, bit[150], pw[150][3];
void sub() {
	while (n) bit[ ++ cnt] = n % 3ll, n /= 3ll;
	rep(i, 0, 2) pw[0][i] = (i == 0 ? 1 : (i == 1 ? x : x * x % mod));
	rep(i, 1, cnt) rep(j, 0, 2) 
		pw[i][j] = pw[i - 1][j] * pw[i - 1][j] % mod * pw[i - 1][j] % mod;
	rep(i, 0, bit[cnt]) f[cnt][i == bit[cnt]][i] = pw[cnt - 1][i];
	dep(i, cnt, 2) rep(j, 0, 2) rep(k, 0, 1) rep(l, 0, 100) {
		if (k and j > bit[i - 1]) continue;
		(f[i - 1][k & (j == bit[i - 1])][l + j] += f[i][k][l] * pw[i - 2][j] % mod) %= mod;
	} pz[0] = 1; rep(i, 1, 100) pz[i] = pz[i - 1] * z % mod;
	rep(i, 0, 100) (ans += (f[1][0][i] + f[1][1][i]) * pz[i] % mod) %= mod;
	printf("%lld\n", ans - 1); return;
}
signed main() {
	scanf("%lld%lld%lld%lld", &n, &x, &y, &z);
	if (y == 1) { sub(); return 0; }
	px[0] = py[0] = pz[0] = 1;
	rep(i, 1, n) px[i] = px[i - 1] * x % mod;
	rep(i, 1, 50) py[i] = py[i - 1] * y % mod;
	rep(i, 1, 50) pz[i] = pz[i - 1] * z % mod;
	rep(i, 1, n) a[i] = a[i >> 1] + (i & 1);
	rep(i, 1, n) b[i] = b[i / 3] + (i % 3);
	rep(i, 1, n) (ans += px[i] * py[a[i]] % mod * pz[b[i]] % mod) %= mod;
	cout << ans << endl; return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 44ms
memory: 223392kb

input:

9134097 778012792 263448561 839843856

output:

887680205

result:

ok 1 number(s): "887680205"

Test #2:

score: 5
Accepted
time: 91ms
memory: 236508kb

input:

9896386 2948513 263418583 271155379

output:

853292631

result:

ok 1 number(s): "853292631"

Test #3:

score: 5
Accepted
time: 92ms
memory: 221940kb

input:

9150910 827328107 842171962 39947937

output:

534921610

result:

ok 1 number(s): "534921610"

Test #4:

score: 5
Accepted
time: 1ms
memory: 7900kb

input:

9586674634211 1 1 58301262

output:

13306748

result:

ok 1 number(s): "13306748"

Test #5:

score: 5
Accepted
time: 0ms
memory: 6012kb

input:

9774917720998 1 1 609549524

output:

825025220

result:

ok 1 number(s): "825025220"

Test #6:

score: 5
Accepted
time: 0ms
memory: 7896kb

input:

9765239207265 422503033 1 719749187

output:

993518920

result:

ok 1 number(s): "993518920"

Test #7:

score: 5
Accepted
time: 1ms
memory: 5988kb

input:

9732354736444 277693641 1 501293609

output:

77844778

result:

ok 1 number(s): "77844778"

Test #8:

score: 0
Runtime Error

input:

9004409828 377918953 449219487 26422407

output:


result:


Test #9:

score: 0
Runtime Error

input:

9579878149 820453354 218842704 133154415

output:


result:


Test #10:

score: 0
Runtime Error

input:

9475807443 305433821 391589421 170059051

output:


result:


Test #11:

score: 0
Runtime Error

input:

484758270277 372146623 410538257 35340632

output:


result:


Test #12:

score: 0
Runtime Error

input:

473458173541 864158404 220259603 529747800

output:


result:


Test #13:

score: 0
Runtime Error

input:

459992983903 359742981 983942229 552405867

output:


result:


Test #14:

score: 0
Runtime Error

input:

462331701308 665849375 563297194 141092054

output:


result:


Test #15:

score: 0
Runtime Error

input:

9061635042931 746632077 302662913 559990819

output:


result:


Test #16:

score: 0
Runtime Error

input:

9653325901537 559549569 638292572 474780356

output:


result:


Test #17:

score: 0
Runtime Error

input:

9640271229478 619740479 644097590 907038757

output:


result:


Test #18:

score: 0
Runtime Error

input:

9781711161203 988850684 154464719 995932763

output:


result:


Test #19:

score: 0
Runtime Error

input:

9156325004698 915375188 316066096 217969045

output:


result:


Test #20:

score: 0
Runtime Error

input:

9042535293051 906265264 156788435 622201740

output:


result: