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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 and , each containing elements. For every integer from to , consider all ordered pairs of indices satisfying and .
Calculate the sequence , 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 , the common length of the two sequences.
- The second line contains exactly integers .
- The third line contains exactly integers .
Output
Print exactly integers in order, separated by spaces. Each value is taken modulo .
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
6
1 2 3 4 5 6
6 5 4 3 2 1
Output
284 90 39 12 10 6
Explanation
For , the valid pairs are , , , , , , and . Their products are , summing to , so . For , only is valid, giving . Grouping pairs with GCD equal to similarly yields . Thus the answer is 284 90 39 12 10 6.