PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000195. Số kỳ diệu thứ N (Nth Magical Number)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Số kỳ diệu thứ N (Nth Magical Number)

Nth Magical Number

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

A positive integer is magical if it is divisible by at least one of aa or bb. Find the nn-th magical number in increasing order, with positions starting at 1.

Since the answer may be large, output that number modulo 109+710^9+7. Do not reduce intermediate search bounds modulo the modulus.

Input

  • The only line contains three integers nn, aa, bb.

Output

  • Print the nn-th magical number modulo 109+710^9+7.

Subtasks

  • Subtask 1 (20 points): 1≤n≤10001\le n\le 1000; 2≤a,b≤1002\le a,b\le 100.
  • Subtask 2 (30 points): 1≤n≤10000001\le n\le 1000000; 2≤a,b≤40002\le a,b\le 4000.
  • Subtask 3 (50 points): 1≤n≤10000000001\le n\le 1000000000; 2≤a,b≤400002\le a,b\le 40000.

Examples

Input

4 2 3

Output

6

Explanation

For n=4n=4, a=2a=2, b=3b=3, the magical numbers begin with 2,3,4,6,8,9,…2,3,4,6,8,9,\ldots. The fourth is 66, so the output is 6 mod (109+7)=66\bmod(10^9+7)=6.