Class Solution

java.lang.Object
g1201_1300.s1201_ugly_number_iii.Solution

public class Solution extends Object
1201 - Ugly Number III.<p>Medium</p> <p>An <strong>ugly number</strong> is a positive integer that is divisible by <code>a</code>, <code>b</code>, or <code>c</code>.</p> <p>Given four integers <code>n</code>, <code>a</code>, <code>b</code>, and <code>c</code>, return the <code>n<sup>th</sup></code> <strong>ugly number</strong>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 3, a = 2, b = 3, c = 5</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> The ugly numbers are 2, 3, 4, 5, 6, 8, 9, 10&hellip; The 3<sup>rd</sup> is 4.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 4, a = 2, b = 3, c = 4</p> <p><strong>Output:</strong> 6</p> <p><strong>Explanation:</strong> The ugly numbers are 2, 3, 4, 6, 8, 9, 10, 12&hellip; The 4<sup>th</sup> is 6.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> n = 5, a = 2, b = 11, c = 13</p> <p><strong>Output:</strong> 10</p> <p><strong>Explanation:</strong> The ugly numbers are 2, 4, 6, 8, 10, 11, 12, 13&hellip; The 5<sup>th</sup> is 10.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n, a, b, c <= 10<sup>9</sup></code></li> <li><code>1 <= a * b * c <= 10<sup>18</sup></code></li> <li>It is guaranteed that the result will be in range <code>[1, 2 * 10<sup>9</sup>]</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • nthUglyNumber

      public int nthUglyNumber(int n, int a, int b, int c)