Original question:
Description
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! horrible!
Aside from loving sweet things, thieves from this area is known to being very greedy. So after a thief takes he number of chocolates for himself, the next thief would take exactly k times more th An the previous one. The value of k (k > 1) is a secret an integer known only to them. It is also known so each thief's bag can carry at most n Chocolates (if they intend to take more, the deal is cancelled) and that there were exactly fourthieves involved.
Sadly, only the thieves know the value of n, but rumours say that the numbers of ways they could has taken T The He chocolates (for a fixed n, and not the fixed k) is M. Ways is considered different if one of the thieves (they should be numbered in the order they take chocolates) took D Ifferent number of chocolates in them.
Mike want to track the thieves down, so he wants to know what their bags is and value of N would help him in that. Please find the smallest possible value of n or him, the rumors is false and there is no Su Chn.
Input
The single line of input contains the integer m(1≤ m ≤10)-the number of ways the Thiev ES might steal the chocolates, as rumours say.
Output
Print the only integer n -the maximum amount of chocolates that thieves ' bags can carry. If there is more than one n satisfying the rumors, print the smallest one.
If There is no such n for a false-rumoured m, print -1.
Sample Input
Input
1
Output
8
Input
8
Output
54
Input
10
Output
-1
Hint
In the first, sample case, the smallest n , leads to exactly one, stealing chocolates is n = 8, whereas the amounts of stealed chocolates is (1, 2, 4, 8) (the number of chocolates stolen by each of the Thie VES).
In the second sample case the smallest n , leads to exactly 8 ways is n = Si with the pos Sibilities: (1, 2, 4, 8), (1, 3, 9, 27), (2, 4, 8, 16), (2, 6, 18, 54), (3, 6, 12, 24), (4, 8, 16, 32), (5, 10, (6, +,-).
There is no. n leading to exactly, ways of stealing chocolates in the third sample case.
Tips: The fun (x) function in the code represents the maximum number of combined species that can be formed when N=X is returned. (N=t*k^3, for a specified K, T is preferable to 1~t).
So that's looking for a minimum x that satisfies fun (x) = = M.
Fun (x) monotonically increase, so use binary search, complexity to meet the requirements of the topic.
Two-time note 1. while (l<=r) to use less than equals, missing equals wrong answe. (the basic requirements of binary search method) 2.types = = M_types, r=mid-1. (In order to find the smallest n, take the leftmost one when multiple consecutive numbers are equal).
There's another place, fun (10e14) = 10e15 It is known that when M takes the extreme case 10E15, corresponds to the largest n is 10e14, so the definition R variable must be defined at least 10E15,(Long Long data range 10e18).
Code:
#include <cstdio>#include<cstring>#include<iostream>using namespacestd;#defineMAX (x, Y) (((x) > (y))? (x): (y))#defineMIN (x, Y) ((() < (y))? (x): (y))#defineABS (x) ((x) >0? ( x):-(x))#definell Long LongConst intINF =0x7fffffff;Const intmaxn=1e15+Tenll Fun (ll x) {ll sum=0; for(LL i=2; i*i*i<=x; i++) {sum+ = x/(i*i*i); } returnsum;}intMain () {ll L=1, r=10e15,mid,ans=-1;//Fun (10e14) = = 10e15; So the maximum n possible value is 10E15 (when there are 10E15 methods at the extreme)ll M_types; CIN>>m_types; while(L<=R) {//l=minimum N, r=maximum N; = To add convenient to find the smallest numbermid=l+ (r-l)/2; ll types=Fun (mid); if(Types <m_types) L=mid+1; Else if(Types >m_types) R=mid-1; Else{//equal also take the left half, because to find the smallest n (find the largest also have methods)ans=mid; R=mid-1; }} cout<<ans<<Endl; return 0;}
Codeforces 689C Mike and chocolate thieves (two points)