Broken Clock
Time limit2sMemory limit256 MB
Given a broken 12-hour analog clock whose second hand moves a/b seconds per real second, count how many times in 24 hours it shows exactly the same time as a correct clock, excluding time zero but including 24 hours.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Implementation
- Solved
- No attempts yet
Problem
They say a stopped clock is right twice a day. But a broken clock is not always a stopped clock. A clock that runs fast, runs slow, or runs backward can match a correct clock fewer than twice or many more times a day.
Hyunuk has many broken clocks. He sets a broken clock and a correct clock to exactly 12:00:00, then counts how many times in the next 24 hours the two clocks show exactly the same time. Every clock is an analog clock whose hands make one full turn every 12 hours, and the hour hand and the minute hand and the second hand all move at the same ratio. The second hand of the broken clock moves seconds during each real second, and the hands run backward when is negative. Do not count the initial alignment at time zero, but count an alignment at exactly 24 hours. Write a program that computes this count for the given speed.
Input
The first line contains two integers and . They satisfy and with . This means the second hand of the broken clock moves seconds per real second. A negative means the clock runs backward.
Output
Print the number of times in 24 hours that the broken clock shows exactly the same hours, minutes, and seconds as the correct clock. Do not count the initial alignment at the start, but count an alignment at exactly 24 hours.
Hint
A stopped clock always shows 12:00:00. It matches the correct clock at the start, after 12 hours, and after 24 hours. The start is excluded, so the answer is 2. A clock that runs backward at the same speed meets the correct clock once every 6 hours, for 4 matches in 24 hours.