P3403 Jump Elevator

Background

To avoid becoming a "salted fish" (idle person), DJL went to srwudi to learn code golf techniques.

Description

srwudi's home is a skyscraper with $h$ 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 $x$ floors; 2. Move up $y$ floors; 3. Move up $z$ 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 $h$, the number of floors of the skyscraper. The second line contains three positive integers, which are $x, y, z$.

Output Format

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

Explanation/Hint

Reachable floors include: $1,5,8,9,10,12,13,14,15$. $1 \le h \le 2^{63} - 1$, $1 \le x, y, z \le 10^5$. Translated by ChatGPT 5