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

#GL0000265. Tích chập LCM (Lcm Convolution)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tích chập LCM (Lcm Convolution)

Lcm Convolution

Source: Library Checker

Version: Phuoc Hung OJ Extended

Problem Statement

You are given two integer sequences a1,a2,…,aNa_1,a_2,\ldots,a_N and b1,b2,…,bNb_1,b_2,\ldots,b_N, each containing NN elements. For every integer kk from 11 to NN, consider all ordered pairs of indices (i,j)(i,j) satisfying 1≤i,j≤N1\le i,j\le N and lcm⁡(i,j)=k\operatorname{lcm}(i,j)=k.

Calculate the sequence c1,c2,…,cNc_1,c_2,\ldots,c_N, where

$$c_k=\sum_{\substack{1\le i,j\le N\\\operatorname{lcm}(i,j)=k}}a_ib_j\pmod{998244353}.$$

Each ordered pair contributes exactly once to its corresponding index. For LCM values greater than N, the pair does not contribute to the output.

Input

  • The first line contains an integer NN, the common length of the two sequences.
  • The second line contains exactly NN integers a1,a2,…,aNa_1,a_2,\ldots,a_N.
  • The third line contains exactly NN integers b1,b2,…,bNb_1,b_2,\ldots,b_N.

Output

Print exactly NN integers c1,c2,…,cNc_1,c_2,\ldots,c_N in order, separated by spaces. Each value is taken modulo 998244353998244353.

Subtasks

  • Subtask 1 (20 points): 1≤N≤201\le N\le20; 0≤ai,bi<9982443530\le a_i,b_i<998244353 for every 1≤i≤N1\le i\le N.
  • Subtask 2 (30 points): 1≤N≤20001\le N\le2000; 0≤ai,bi<9982443530\le a_i,b_i<998244353 for every 1≤i≤N1\le i\le N.
  • Subtask 3 (50 points): 1≤N≤1061\le N\le10^6; 0≤ai,bi<9982443530\le a_i,b_i<998244353 for every 1≤i≤N1\le i\le N.

Examples

Input

6
1 2 3 4 5 6
6 5 4 3 2 1

Output

6 27 34 65 42 125

Explanation

For k=1k=1, the only pair is (1,1)(1,1), contributing a1b1=1⋅6=6a_1b_1=1\cdot6=6. For k=2k=2, the pairs (1,2),(2,1),(2,2)(1,2),(2,1),(2,2) contribute 5,12,105,12,10, summing to 2727. For k=6k=6, the pairs (1,6)(1,6), (2,3)(2,3), (2,6)(2,6), (3,2)(3,2), (3,6)(3,6), (6,1)(6,1), (6,2)(6,2), (6,3)(6,3), and (6,6)(6,6) contribute 1+8+2+15+3+36+30+24+6=1251+8+2+15+3+36+30+24+6=125. Grouping pairs with LCM 3,4,53,4,5 gives 34,65,4234,65,42. The answer is 6 27 34 65 42 125.