Solved LeetCode program · 878 of 1,000
#1201 · Ugly Number III
Original English source
Keep a shared firstdiv of 0. Keep a shared seconddiv of 0. Keep a shared thirddiv of 0. Set firstdiv to 2. Set seconddiv to 3. Set thirddiv to 5. Keep a shared divisor of 0. Keep a shared multiple of 0. Keep a shared tally of 0.
To gcd from first (a whole number) with second (a whole number). If second is 0, set divisor to first, return. Gcd from second with (first modulo second).
To lcm from first (a whole number) with second (a whole number). Gcd from first with second. Set multiple to (first divided by divisor) times second.
To count from value (a whole number). Set tally to value divided by firstdiv. Increase tally by (value divided by seconddiv). Increase tally by (value divided by thirddiv). Lcm from firstdiv with seconddiv. The ab is multiple. Lcm from firstdiv with thirddiv. The ac is multiple. Lcm from seconddiv with thirddiv. The bc is multiple. Lcm from ab with thirddiv. The abc is multiple. Decrease tally by (value divided by ab). Decrease tally by (value divided by ac). Decrease tally by (value divided by bc). Increase tally by (value divided by abc).
The rank is 3. The low is 1. The high is 6.
Repeat while low is less than high.
The middle is (low plus high) divided by 2. Count from middle. If tally is at least rank, set high to middle. If tally is less than rank, set low to middle plus 1.
Show low.
Expected stdout
4