#P3403. Srwudi's Skyscraper Jump Machine
Srwudi's Skyscraper Jump Machine
Srwudi's Skyscraper Jump Machine
Srwudi's home is a skyscraper with \(h\) floors. To accommodate the increasing number of visitors, srwudi has modified a jump machine that now allows visitors to more easily reach higher floors. The jump machine can move in one of the following four ways:
- Move upward by \(x\) floors.
- Move upward by \(y\) floors.
- Move upward by \(z\) floors.
- Return to the first floor.
DJL arrives at srwudi's home on the first floor at the same time as the jump machine. He wonders how many distinct floors he can reach by using the jump machine. Note that DJL may use the machine any number of times (possibly resetting back to the first floor) as long as he does not exceed the \(h\)th floor.
Formally, starting from floor 1, a floor \(f\) (where \(1 \le f \le h\)) is reachable if and only if \(f=1+s\) for some nonnegative integer \(s\) that can be expressed in the form \(s=ax+by+cz\) (with \(a,b,c \ge 0\)) where \(1+s \le h\).
inputFormat
The input consists of a single line containing four integers \(h, x, y, z\), where \(h\) is the number of floors of the skyscraper and \(x, y, z\) are the numbers of floors the jump machine can move upward in one move.
\(1 \le h \le 10^5\) and \(1 \le x,y,z \le h\).
outputFormat
Output a single integer denoting the number of distinct reachable floors using the jump machine.
sample
10 2 3 5
9