Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    878 - Nth Magical Number\.

    Hard

    A positive integer is magical if it is divisible by either a or b.

    Given the three integers n, a, and b, return the <code>n<sup>th</sup></code> magical number. Since the answer may be very large, return it modulo <code>10<sup>9</sup> + 7</code>.

    Example 1:

    Input: n = 1, a = 2, b = 3

    Output: 2

    Example 2:

    Input: n = 4, a = 2, b = 3

    Output: 6

    Constraints:

    • <code>1 <= n <= 10<sup>9</sup></code>

    • <code>2 <= a, b <= 4 * 10<sup>4</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer nthMagicalNumber(Integer n, Integer a, Integer b)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait