#P2810. Cows’ Stealthy Feast

    ID: 16071 Type: Default 1000ms 256MiB

Cows’ Stealthy Feast

Cows’ Stealthy Feast

Security reports say that during his gaming shift, the guard saw 4 cows rolling out of the campus. These cows are not only extremely greedy but also orderly. When they sneak food, they form a queue such that each subsequent cow eats an amount that is an integer multiple of what the previous cow ate; let that multiplier be \(k\) (with \(k>1\)). Each cow eats the food one ton at a time, and no cow will eat more than \(m\) tons of food because if they try to exceed \(m\), they will instantly turn to ashes. In other words, if a cow is unable to take another ton (because doing so would exceed \(m\)), it will attack its companions and then commit suicide.

It turns out that there is a particular number \(n\) (\(n\le 10^{15}\)) which represents the total number of safe schemes in which the cows can all sneak food together (i.e. all 4 cows manage to eat their planned amounts, each amount being an uninterrupted sequence of tons taken one by one, without exceeding \(m\)). In each valid scheme the amounts eaten by the 4 cows form a geometric progression: \(a, ka, k^2a, k^3a\) where all terms are positive integers and each term is at most \(m\).

Your task is: given \(n\), determine the value of \(m\) such that the number of valid schemes is exactly \(n\). If more than one valid \(m\) exists, output the smallest possible one. If no such \(m\) exists, output \(-1\) and don’t forget to complain about the security guard!

Note:

  1. The valid schemes come from picking a positive integer \(a\) and an integer \(k>1\) satisfying \(a \le m,\; k\, a \le m,\; k^2a \le m,\; k^3a \le m\).
  2. This is equivalent to \(a \le \frac{m}{k^3}\). Hence, the total number of safe schemes for a given \(m\) is:

[ f(m)=\sum_{k=2}^{\lfloor m^{1/3}\rfloor} \left\lfloor \frac{m}{k^3} \right\rfloor. ]

You are given \(n\) and must find the smallest \(m\) such that \(f(m)=n\). If no such \(m\) exists, output \(-1\).

inputFormat

The input consists of a single integer \(n\) (\(0\le n\le 10^{15}\)), which is the total number of safe schemes in which the cows can all sneak food together.

outputFormat

Output a single integer: the smallest possible \(m\) such that the number of valid schemes is exactly \(n\). If no such \(m\) exists, output \(-1\).

sample

0
1

</p>