Coin System
Time limit2sMemory limit512 MB
Given A, B and X, count the values Y so that coins X and Y generate exactly the same set of prices as A and B, or print -1 if infinitely many.
- Level
Medium7 of 10
- Topics
- Number theory, Math, Greedy
- Solved
- No attempts yet
Problem
In the country where Youngsun lives, there are two kinds of coins, A and B. Every product in this country has a price of the form ( and are non-negative integers), so these two coins are enough.
One day Youngsun wondered whether a different coin system could also make the price of every product in this country.
Given A, B, and X, write a program that finds the values of two coins that can make every price of the form . One coin has value X and the other has value Y (). Since X is given in the input, the task is to find Y. In the new system each coin can also be used any non-negative integer number of times, and Y is a positive integer.
Input
The first line contains A, B, and X. ()
Output
Print the number of possible values of Y on the first line. If there are infinitely many possible values of Y, print -1.