Date Cycle Calculation
InterviewTime limit2sMemory limit4 MB
Find the smallest year whose Earth, Sun, and Moon cycle counters, each resetting at fixed limits, match a given triple of values.
- Level
Easy3 of 10
- Topics
- Simulation, Math, Brute force
- Solved
- No attempts yet
Problem
In Jun-gyu's country, years are represented differently from the calendar we usually use. A year in this country is written as three numbers, E, S, and M, representing the cycles of Earth, Sun, and Moon.
Each number has its own range.
1 <= E <= 151 <= S <= 281 <= M <= 19
Year 1 in our calendar is written as 1 1 1 in this system. Every year, all three numbers increase by 1. If a number passes the end of its range, it becomes 1 again.
So year 15 is written as 15 15 15, but the next year, year 16, is written as 1 16 16 because E cannot exceed 15.
Given E, S, and M, determine which year in our calendar is represented by those three numbers. Print the earliest possible year.
Input
The first line contains three integers E, S, and M, separated by spaces. The input always satisfies the ranges above.
Output
Print the earliest year represented by E S M. Since 1 1 1 is always year 1, the answer is always positive.