Friendly Brothers
Time limit2sMemory limit128 MB
Given a reduced fraction a/b, find the shortest repeating turn pattern (length at most 60) of two people eating half the remaining cake so one person's total share equals a/b.
- Level
Medium6 of 10
- Topics
- Number theory, Math, Bit manipulation, Brute force
- Solved
- No attempts yet
Problem
Youngsik and Minsik are sharing a cake. Whenever someone takes a turn, that person eats exactly half of the cake that remains.
If they alternate in the order Youngsik, Minsik, Youngsik eats the following amounts.
In this case, Youngsik eats 2/3 of the whole cake, and Minsik eats 1/3.
Now the two brothers will repeat a fixed pattern forever. Each character of the pattern represents one turn; after the last character, the pattern starts again from the beginning. Youngsik is written as *, and Minsik is written as -.
For the repeated pattern Youngsik, Minsik, Youngsik, the amounts are taken as follows.
With this pattern, Youngsik eats 5/7 of the whole cake.
You are given the target amount of cake Youngsik must eat as a reduced fraction a/b. Find the shortest repeating pattern that makes Youngsik eat exactly that amount.
Input
The first line contains two integers a and b. They are the numerator and denominator of the reduced fraction a/b.
Output
Print the eating pattern on the first line. In the pattern, print Youngsik's turns as * and Minsik's turns as -.
If no pattern of length at most 60 exists, print -1. If multiple patterns are possible, print the shortest one.
Constraints
0 <= a <= b <= 2^63 - 1aandbare relatively prime.