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

#GL0000264. Tích chập GCD (Gcd Convolution)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tích chập GCD (Gcd Convolution)

Gcd 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 gcd⁡(i,j)=k\gcd(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\\\gcd(i,j)=k}}a_ib_j\pmod{998244353}.$$

Each ordered pair contributes exactly once to its corresponding index. The GCD of two indices in this range is always between 1 and N.

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

284 90 39 12 10 6

Explanation

For k=2k=2, the valid pairs are (2,2)(2,2), (2,4)(2,4), (2,6)(2,6), (4,2)(4,2), (4,6)(4,6), (6,2)(6,2), and (6,4)(6,4). Their products are 10,6,2,20,4,30,1810,6,2,20,4,30,18, summing to 9090, so c2=90c_2=90. For k=6k=6, only (6,6)(6,6) is valid, giving c6=a6b6=6c_6=a_6b_6=6. Grouping pairs with GCD equal to 1,3,4,51,3,4,5 similarly yields 284,39,12,10284,39,12,10. Thus the answer is 284 90 39 12 10 6.