#P9645. Find the k-hour Clock Value
Find the k-hour Clock Value
Find the k-hour Clock Value
A k-hour clock is a day keeping method defined as follows:
- A day is divided into $k$ hours, where the $i$-th hour is called the $(i-1)$ o' clock.
- If it is $x$ o'clock now, after 1 hour it becomes $(x+1)$ o'clock if $0 \le x < k-1$.
- If it is $(k-1)$ o'clock now, after 1 hour it becomes $0$ o'clock.
You are given that the current time is $x$ o'clock, and after $y$ hours it will be $z$ o'clock. It is guaranteed that a valid $k$ exists. In particular, note that if $x+y=z$, the clock system can be any $k > \max(x,z)$; in this case, output the minimum possible value $k=\max(x,z)+1$. Otherwise, if $x+y \neq z$, there exists an integer $m\ge1$ such that $$ x+y = m\,k + z. $$ This implies that $$ k = \frac{x+y-z}{m}, $$ and among all divisors of $x+y-z$ that are greater than $\max(x,z)$, you should output the smallest one.
Input/Output note: The input contains three integers $x$, $y$, $z$ in one line. Output the appropriate value of $k$.
inputFormat
The input consists of a single line containing three integers x
, y
, and z
separated by spaces.
outputFormat
Output a single integer — the value of $k$ satisfying the clock condition described above.
sample
2 3 0
5