Fractran
Time limit1sMemory limit128 MB
Given a list of fractions and a start value, repeatedly apply the first fraction that keeps the value an integer, and report the first m exponents of powers of two that appear.
- Level
Medium7 of 10
- Topics
- Simulation, Math, Number theory, Implementation
- Solved
- No attempts yet
Problem
To play the "fraction game" for a given list of fractions and a starting integer , repeatedly multiply the integer you currently hold (initially ) by the earliest in the list for which the product is an integer. As soon as no such exists, the game stops.
Formally, define the sequence by and , where is the smallest index with such that is an integer while are not.
For example, with the eight fractions , , , , , , , and , the game produces the finite sequence . In general the sequence may be infinite.
Given a fraction list and a starting integer, we are interested only in the powers of that appear in the sequence.
Input
The input contains several test cases. Each test case begins with three integers , , and , where , , and . Then follow the fractions : for each fraction the numerator is given first, then the denominator. Both are positive integers less than whose greatest common divisor is . The last test case is followed by a single .
Output
For each test case, output on one line the numbers , separated by single spaces, such that are the first powers of that occur in the sequence. You may assume that at least powers of occur among the first elements of the sequence.