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

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

1 lộ trình

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 mm rows and nn columns, indexed from 11. The entry in row ii and column jj equals i⋅ji\cdot j.

Take all mnmn entries, including repeated values, and sort them in nondecreasing order. Find the value in position kk, with positions starting from 1. Equal entries contribute separate positions.

Input

  • The only line contains three integers mm, nn, and kk.

Output

  • Print one integer: the kk-th smallest table entry.

Subtasks

  • Subtask 1 (20 points): 1≤m,n≤301\le m,n\le 30; 1≤k≤mn1\le k\le mn.
  • Subtask 2 (30 points): 1≤m,n≤20001\le m,n\le 2000; 1≤k≤mn1\le k\le mn.
  • Subtask 3 (50 points): 1≤m,n≤300001\le m,n\le 30000; 1≤k≤mn1\le k\le mn.

Examples

Input

3 3 5

Output

3

Explanation

For m=n=3m=n=3, the rows are [1,2,3][1,2,3], [2,4,6][2,4,6], and [3,6,9][3,6,9]. Sorting all nine entries, including duplicates, gives [1,2,2,3,3,4,6,6,9][1,2,2,3,3,4,6,6,9]. The fifth entry is 33.