Kurt Gödel
Time limit10sMemory limit512 MB
Given a word length, a prime p, and a remainder r, find all words whose Godel number has length i and leaves remainder r mod p.
- Level
Medium6 of 10
- Topics
- Number theory, Brute force, Math
- Solved
- No attempts yet
Problem
Kurt Friedrich Gödel was an Austrian mathematician and philosopher. Earlier scientist philosophers such as Isaac Newton and Immanuel Kant influenced him, and he later influenced mathematicians and philosophers such as Bertrand Russell. Gödel used Gödel numbering in the proof of his incompleteness theorem, which tests the boundary of mathematics and logic themselves. That proof puts him next to Aristotle among the most important logicians in history.
Here is how Gödel numbering works. It assigns a number to every symbol. In this problem the symbols are the capital letters A to Z, mapped in order to the natural numbers 1 to 26, so A becomes 1, B becomes 2, and the last letter Z becomes 26. The word KURT then becomes the sequence (11, 21, 18, 20). The sequence is written as a product of prime powers: a sequence is encoded as , where is the -th prime. The Gödel number of KURT is therefore .
The Gödel number of a long word is very large. Your friend Albert wants to leave you a message written with Gödel numbers, but he is too lazy to write out every digit. Albert writes a Gödel number as a triple , where is the length of the original word, is a prime, and is the remainder of divided by . Albert did not notice that two different words can produce the same triple. The Gödel numbers of EA and JA are 96 and 3072, yet Albert may write for both of them. Decode Albert's message.
Input
There are at most 30 test cases. Each test case is one line holding three integers separated by spaces. The first integer is the length of the word. The second integer is the remainder of the Gödel number divided by . The third integer is the prime used in the modulo operation. always holds. The input ends with a line holding three zeros, and that line is not a test case. A word consists only of the capital letters A to Z.
Output
Print one line for each test case. If exactly one word of length produces the given triple, print that word. If two or more such words exist, print ambiguous. If no such word exists, print not a word.