PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000196. Số xấu thứ N với ba ước số (Ugly Number III)
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ố xấu thứ N với ba ước số (Ugly Number III)
Ugly Number III
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given four positive integers , call a positive integer ugly if it is divisible by at least one of .
List all ugly numbers in strictly increasing order, starting from position 1, and output the -th one. A number divisible by several of these divisors is counted only once.
The answer is guaranteed not to exceed .
Input
- One line containing four integers , , , .
Output
- Print the -th ugly number.
Subtasks
- Subtask 1 (20 points): ; ; ; answer .
- Subtask 2 (30 points): ; ; ; answer .
- Subtask 3 (50 points): ; ; answer .
Examples
Input
3 2 3 5
Output
4
Explanation
The first eligible numbers are . Their positions start at 1, so the third number is 4. A common multiple, such as , is counted once, not twice.