PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000188. Phần tử nhỏ thứ K trong bảng nhân (Kth Smallest Number in Multiplication Table)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Phần tử nhỏ thứ K trong bảng nhân (Kth Smallest Number in Multiplication Table)
Kth Smallest Number in Multiplication Table
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Consider a multiplication table with rows and columns, indexed from . The entry in row and column equals .
Take all entries, including repeated values, and sort them in nondecreasing order. Find the value in position , with positions starting from 1. Equal entries contribute separate positions.
Input
- The only line contains three integers , , and .
Output
- Print one integer: the -th smallest table entry.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
3 3 5
Output
3
Explanation
For , the rows are , , and . Sorting all nine entries, including duplicates, gives . The fifth entry is .