eolymp
bolt
Try our new interface for solving problems
Məsələlər

Factoradic Numbers

Factoradic Numbers

In the factoradic number system, numbers are written similarly as in the standard decimal system, but the positions of digits have different meanings: The first (from the right) digit is always \textbf{0} or \textbf{1}, meaning \textbf{0} × \textbf{1}! or \textbf{1} × \textbf{1}!, respectively. The second digit may be \textbf{0}, \textbf{1} or \textbf{2}, meaning \textbf{0} × \textbf{2}!, \textbf{1} × \textbf{2}! or \textbf{2} × \textbf{2}!, and so on: the digit \textbf{c_i} at \textbf{i}-th position belongs to the set \{\textbf{0}, \textbf{1}, ..., \textbf{i}\} and has value \textbf{c_i} × \textbf{i}!. For example, the factoradic number \textbf{1310} is \textbf{1} × \textbf{4}! + \textbf{3} × \textbf{3}! + \textbf{1} × \textbf{2}! + \textbf{0} × \textbf{1}! = \textbf{44} in decimal system. It can be easily proven that every number has a unique factoradic representation. Given two nonnegative numbers in factoradic system, output their product in the same system. No trailing zeros are allowed, only the number zero is written simply as \textbf{0}. \InputFile The first line contains the number \textbf{t} of test cases. The test cases follow. A test case contains four lines: the first two of them describe the first factor, the last two - the other factor. Each factor is described by its length \textbf{d} (\textbf{1} ≤ \textbf{d} ≤ \textbf{2000}) on the first line, and \textbf{d} space-separated integers denoting its digits on the second line. The digits follow the format described in the statement. \OutputFile For each test case, your program should write a single line containing the factoradic representation of the product - output only its digits, from left to right, space-separated.
Zaman məhdudiyyəti 2 saniyə
Yaddaşı istafadə məhdudiyyəti 128 MiB
Giriş verilənləri #1
1
4
1 0 0 1
4
1 0 0 1
Çıxış verilənləri #1
5 1 0 0 1
Mənbə 2013 Petrozavodsk Winter Training Camp, Jagiellonian University Contest, January 25, Problem F