#P8350. [SDOI/SXOI2022] 进制转换

    ID: 9437 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>各省省选2022山东O2优化山西

[SDOI/SXOI2022] 进制转换

Problem Description

When Little D was two years old, he already learned base conversion.

So he wants to ask you: for all numbers between 1n1 \sim n, what are the sums of digits of this number in binary and ternary, respectively.

For ii, let the sums of digits in binary and ternary be a(i)a(i) and b(i)b(i), respectively. For example, for i=114i = 114, its binary representation is (1110010)2(1110010)_2, and its ternary representation is (11020)3(11020)_3, so a(i)a(i) and b(i)b(i) are both 44.

Little D wants to know whether you can really compute base conversions correctly for all numbers from 11 to nn, so he asks what

i=1nxiya(i)zb(i)\sum\limits_{i = 1}^n x^i y^{a(i)} z^{b(i)}

is. Since the answer is very large, output the result modulo 998244353998244353.

Input Format

There is only one line with four integers, in order: n,x,y,zn, x, y, z.

Output Format

Output one line with one integer, representing the answer.

123456 12345 234567 3456789

664963464

1234567891 123 1 12345

517823355

9876543210987 1284916 83759265 128478129

115945104

Hint

Constraints

This problem has 2020 test points.

  • For test points 1,2,31,2,3, n107n \le 10^7.
  • For test points 4,54,5, x=y=1x = y = 1.
  • For test points 6,76,7, y=1y = 1.
  • For test points 8,9,108,9,10, n<1010n < 10^{10}.
  • For test points 11,12,13,1411,12,13,14, n5×1011n \le 5 \times 10^{11}.

For all test points, 1n10131 \le n \le 10^{13}, 1x,y,z<9982443531 \le x, y, z < 998244353.

Translated by ChatGPT 5