Secret Code
Time limit1sMemory limit128 MB
Convert a complex number X into base-B positional digits with a Gaussian-integer complex base, or report failure if impossible.
- Level
Medium6 of 10
- Topics
- Math, Number theory, Implementation
- Solved
- No attempts yet
Problem
The sarcophagus is locked by a secret numerical code. To open it you must know the code and set it exactly on top of the sarcophagus; if an incorrect code is entered, the tickets inside catch fire immediately and are lost forever. The code consists of up to 100 integers.
An archaeologist obtained a copy of the code. Afraid that it might fall into the wrong hands, he encoded the numbers in a special way. He chose a complex number whose absolute value is greater than that of every number to be encoded. He then treated the sequence as the digits of the positional numeral system with base , encoding them as the single number
Given the number and the base , recover the digits that express in base .
Input
The first line contains the number of test cases . Each of the next lines contains four integers (, ), where and . Here is the base of the system () and is the number to express.
Output
For each test case, print a single line containing the digits separated by commas. The digits must satisfy all of the following:
- for every
- if then
The representation satisfying these conditions is unique. If no such representation exists, print exactly The code cannot be decrypted.