Ath Magical Number

Given three positive integers A, B and C. A positive integer is magical if it is divisible by either B or C.

Return the A-th magical number. Since the answer may be very large, return it modulo 109 + 7.



Input Format

The first argument given is an integer A.
The second argument given is an integer B.
The third argument given is an integer C.

Output Format

Return the A-th magical number modulo (10^9+7).

Constraints

1 <= A <= 10^9
2 <= B, C <= 40000 

For Example

Input 1:
    A = 1
    B = 2
    C = 3
Output 1:
    2
Explanation 1:
    1st magical number is 2.

Input 2:
    A = 4
    B = 2
    C = 3
Output 2:
    6
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Ath Magical Number on Interview Code Editor
Sign Up
to access hints and editorial solutions for Ath Magical Number

Discussion


Loading...
Click here to start solving coding interview questions