------
## 最终结论
```python
def nthMagicalNumber(N, A, B):
    MOD = 10**9 + 7

    def gcd(x, y):
        while y:
            x, y = y, x % y
        return x

    L = A // gcd(A, B) * B

    def magical_count(x):
        return x // A + x // B - x // L

    low, high = 1, N * min(A, B)
    while low < high:
        mid = (low + high) // 2
        if magical_count(mid) < N:
            low = mid + 1
        else:
            high = mid
    
    return low % MOD
```