Under construction

Still being built. Things may change

Chocolate Bar

Time limit1sMemory limit2048 MB

Summary
Given an N by M chocolate bar and a target area K, find the fewest splits needed so that some pieces total exactly K.
Level

Medium5 of 10

Topics
Math, Brute force
Solved
No attempts yet

Problem

You have a chocolate bar shaped like a rectangle. Originally, the bar has width NN and height MM. In this problem, (n×m)(n \times m) denotes a chocolate bar with width nn and height mm.

You want to eat chocolate with a total area of exactly KK. However, you always eat a bar as a whole. If you eat a bar (n×m)(n \times m), you eat all of its area n⋅mn \cdot m.

You may perform any of the following operations any number of times, including zero.

  • Pick one bar (n×m)(n \times m) and split it into two bars (n×i)(n \times i) and (n×(m−i))(n \times (m - i)), where ii is an integer with 1≤i<m1 \le i < m.
  • Pick one bar (n×m)(n \times m) and split it into two bars (i×m)(i \times m) and ((n−i)×m)((n - i) \times m), where ii is an integer with 1≤i<n1 \le i < n.

Find the minimum number of operations needed so that you can eat some bars with a total area of exactly KK.

Input

Three integers NN, MM, and KK are given (1≤N,M≤1061 \le N, M \le 10^6, 1≤K≤N⋅M1 \le K \le N \cdot M).

Output

Print a single integer, the minimum number of operations needed so that some bars can be eaten with a total area of exactly KK.

Examples3

  1. Example 1

    Input
    4 4 10
    
    Expected output
    2
    
  2. Example 2

    Input
    5 6 6
    
    Expected output
    1
    
  3. Example 3

    Input
    1 1 1
    
    Expected output
    0