#P3403. 跳楼机

跳楼机

Description

srwudi's home is a skyscraper with hh floors. Because more and more newbies are coming to learn, srwudi modified an elevator so that visitors can go upstairs more easily.

After the modification, the elevator can move in the following four ways:

  1. Move up xx floors;
  2. Move up yy floors;
  3. Move up zz floors;
  4. Return to the first floor.

One day at noon, DJL arrived at srwudi's home. He is now on the first floor, and the elevator happens to be on the first floor as well. DJL wants to know how many floors he can reach by taking the elevator.

Input Format

The first line contains an integer hh, the number of floors of the skyscraper.

The second line contains three positive integers, which are x,y,zx, y, z.

Output Format

Output a single integer, the number of floors DJL can reach.

15
4 7 9

9

33333333333
99005 99002 100000

33302114671

Hint

Reachable floors include: 1,5,8,9,10,12,13,14,151,5,8,9,10,12,13,14,15.

1h26311 \le h \le 2^{63} - 1, 1x,y,z1051 \le x, y, z \le 10^5.

Translated by ChatGPT 5