PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000392. Tích chập Dirichlet và tổng tiền tố (Dirichlet Convolution and Prefix Sums)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tích chập Dirichlet và tổng tiền tố (Dirichlet Convolution and Prefix Sums)

Dirichlet Convolution and Prefix Sums

Source: Library Checker

Version: Phuoc Hung OJ Extended

Problem Statement

For a positive integer NN, define

QN={⌊N/i⌋:1≤i≤N}.Q_N=\{\lfloor N/i\rfloor:1\le i\le N\}.

Write its distinct elements in ascending order as a0<⋯<ak−1a_0<\cdots<a_{k-1}.

You are given the prefix sums F(x)=∑i=1xf(i)F(x)=\sum_{i=1}^x f(i) and G(x)=∑i=1xg(i)G(x)=\sum_{i=1}^x g(i), modulo 998244353998244353, only for x∈QNx\in Q_N. The individual terms are not provided.

For the Dirichlet convolution h(n)=∑uv=nf(u)g(v)h(n)=\sum_{uv=n}f(u)g(v), calculate H(x)=∑n=1xh(n) mod 998244353H(x)=\sum_{n=1}^x h(n)\bmod998244353 for every x∈QNx\in Q_N in ascending order.

Input

A line containing 1 (one case per PHOJ file), followed by NN, a line of the kk values F(aj)F(a_j) and a line of the kk values G(aj)G(a_j).

Full bound: N≤1012N\le10^{12}, matching the original Library Checker bound. The optimized quotient-table algorithm replaces the earlier slower implementation.

Output

The kk prefix sums H(aj)H(a_j) modulo 998244353998244353, separated by spaces.

Subtasks

  • Subtask 1 (20 points): 1≤N≤1001\le N\le100, 0≤F(aj),G(aj)<9982443530\le F(a_j),G(a_j)<998244353, T=1T=1.

  • Subtask 2 (30 points): 1≤N≤1061\le N\le10^6, 0≤F(aj),G(aj)<9982443530\le F(a_j),G(a_j)<998244353, T=1T=1.

  • Subtask 3 (50 points): 1≤N≤10121\le N\le10^{12}, 0≤F(aj),G(aj)<9982443530\le F(a_j),G(a_j)<998244353, T=1T=1.

Examples

Input

1
10
1 2 3 5 10
1 2 3 5 10

Output

1 3 5 10 27

Explanation

Q10={1,2,3,5,10}Q_{10}=\{1,2,3,5,10\}. For f(n)=g(n)=1f(n)=g(n)=1, both prefixes equal xx. The convolution h(n)h(n) counts positive divisors of nn; its cumulative values at 1,2,3,5,101,2,3,5,10 are 1,3,5,10,271,3,5,10,27.