NEERC '07 Northern E - Elevator

View as PDF

Submit solution

Points: 17
Time limit: 2.0s
Memory limit: 64M

Problem type

Edward works as an engineer for Non-trivial Elevators: Engineering, Research and Construction (NEERC). His new task is to design a brand new elevator for a skyscraper with h floors.

Edward has an idée fixe: he thinks that four buttons are enough to control the movement of the elevator. His last proposal suggests the following four buttons:

  • Move a floors up.
  • Move b floors up.
  • Move c floors up.
  • Return to the first floor.

Initially, the elevator is on the first floor. A passenger uses the first three buttons to reach the floor she needs. If a passenger tries to move a, b or c floors up and there is no such floor (she attempts to move higher than the h-th floor), the elevator doesn't move.

To prove his plan worthy, Edward wants to know how many floors are actually accessible from the first floor via his elevator. Help him calculate this number.

Input Specification

The first line of the input file contains one integer h — the height of the skyscraper (1 \le h \le 10^{18}). The second line contains three integers a, b and c — the parameters of the buttons (1 \le a, b, c \le 100\,000).

Output Specification

Output one integer number — the number of floors that are reachable from the first floor.

Sample Input

15
4 7 9

Sample Output

9

Comments


  • 0
    a_sad_javamain  commented on Dec. 29, 2020, 9:31 p.m.

    Why is the answer for the sample case 9? From my understanding of the question only floors 1, 5, 8, 9, 10, 12, 13, 14 can be reached.


    • 3
      d  commented on Dec. 30, 2020, 12:30 a.m.

      You can use 7 twice to reach 15.


  • 3
    Kirito  commented on Aug. 19, 2020, 11:37 a.m.

    For those interested, remaining problems in the set can be found on Codeforces.