Codeforces Round #361 (Div. 2)C. Mike and Chocolate Thieves

链接:http://codeforces.com/contest/689/problem/C

题意:有4个数,a[1]~a[4],a[i+1]=k*a[i],k>1,只要有一个a[i]不同就算不同的数列。求最小的n使得恰好有m个不同的数列存在并且最大的数a[4]<=n,无解输出-1。

分析:直接二分答案,然后枚举k,计算有多少起点a[1]满足条件。

代码:

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=100010;
const int MAX=1000000100;
const int mod=100000000;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000007;
const int INF=1000000010;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned long long ull;
ll cala(ll x,ll m) {
    ll i,ret=0;
    for (i=2;i*i*i<=x;i++) {
        ret+=x/(i*i*i);
        if (ret>m) return ret;
    }
    return ret;
}
int main()
{
    ll m,l=3,r=1e18,mid=(l+r)>>1;
    scanf("%I64d", &m);
    while (l+1<r)
    if (cala(mid,m)>=m) { r=mid;mid=(l+r)>>1; }
    else { l=mid;mid=(l+r)>>1; }
    if (cala(r,m)==m) printf("%I64d\n", r);
    else printf("-1\n");
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值