Gathering the Followers
InterviewTime limit2sMemory limit1024 MB
Given each follower's visit period d_i and the weekday s of the last joint meeting, find the weekday of the next joint meeting.
- Level
Easy3 of 10
- Topics
- Math, Number theory
- Solved
- No attempts yet
Statement
Grindelwald wants to gather his followers. However, he cannot do it on just any day. Grindelwald has followers, numbered from 1 to . Follower visits the meeting place every days, based on personal beliefs (that is, the interval between two consecutive visits by follower is days). Grindelwald remembers that the last time all his followers appeared at the meeting place together, it was on day of the week. Help him find the number of the day of the week on which all followers will next be at the meeting place together.
Input
The first line contains two integers and (, ). The second line contains integers ().
Output
Print a single integer from 1 to 7: the number of the day of the week on which all followers will next be at the meeting place together. A week has 7 days, which Grindelwald numbered from 1 to 7 in order.