#GL0000392. Tích chập Dirichlet và tổng tiền tố (Dirichlet Convolution and Prefix Sums)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 , define
Write its distinct elements in ascending order as .
You are given the prefix sums and , modulo , only for . The individual terms are not provided.
For the Dirichlet convolution , calculate for every in ascending order.
Input
A line containing 1 (one case per PHOJ file), followed by , a line of the values and a line of the values .
Full bound: , matching the original Library Checker bound. The optimized quotient-table algorithm replaces the earlier slower implementation.
Output
The prefix sums modulo , separated by spaces.
Subtasks
-
Subtask 1 (20 points): , , .
-
Subtask 2 (30 points): , , .
-
Subtask 3 (50 points): , , .
Examples
Input
1
10
1 2 3 5 10
1 2 3 5 10
Output
1 3 5 10 27
Explanation
. For , both prefixes equal . The convolution counts positive divisors of ; its cumulative values at are .