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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 or . Find the -th magical number in increasing order, with positions starting at 1.
Since the answer may be large, output that number modulo . Do not reduce intermediate search bounds modulo the modulus.
Input
- The only line contains three integers , , .
Output
- Print the -th magical number modulo .
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
4 2 3
Output
6
Explanation
For , , , the magical numbers begin with . The fourth is , so the output is .