whust 2016 warm up G ||codeforces 689C. Mike and Chocolate Thieves

cf689C

题意:给出一个m。。问恰好使得不超过某个n的a*b^3(a,b是正整数)的方案数为m的n是多少。。。

思路:暴力+二分。。。

/* ***********************************************
Author :111qqz
Created Time :2016年07月18日 星期一 15时58分55秒
File Name :code/2016whust/G.cpp
************************************************ */
 1#include <cstdio>
 2#include <cstring>
 3#include <iostream>
 4#include <algorithm>
 5#include <vector>
 6#include <queue>
 7#include <set>
 8#include <map>
 9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
 1using namespace std;
 2const double eps = 1E-8;
 3const int dx4[4]={1,0,0,-1};
 4const int dy4[4]={0,-1,1,0};
 5const int inf = 0x3f3f3f3f;
 6LL m,n;
 7LL ans;
 8LL cal( LL x)
 9{
10    LL res = 0LL;
11    for ( LL i =2 ; i * i * i <= x ; i++)
12	res+=x/(i*i*i);
13    return res;
14}
15int main()
16{
17	#ifndef  ONLINE_JUDGE 
18	freopen("code/in.txt","r",stdin);
19  #endif
	cin>>m;
	n = 0 ;
1	LL cur = 1LL<<60;
2//	cout<<"cur:"<<cur<<endl;
3	while (cur!=0LL)
4	{
5	    LL tmp = cal(n+cur);
6	    if (tmp<m) n +=cur;
1	    cur >>=1LL;
2	}
3	n++;
4//	cout<<" n:"<<n<<endl;
5	if (cal(n)!=m) ans = -1;
6	else ans =  n;
	cout<<ans<<endl;
1  #ifndef ONLINE_JUDGE  
2  fclose(stdin);
3  #endif
4    return 0;
5}