cf B. Making Sequences is Fun

http://codeforces.com/contest/373/problem/B

用二分枚举长度就可以。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define LL __int64
using namespace std; LL w,m,k; bool ok(LL c)
{
LL ans=;
LL x2=m+c-;
int t1=;
LL b=x2;
while(b)
{
b/=;
t1++;
}
int t2=;
LL b1=m;
while(b1)
{
b1/=;
t2++;
}
if(t1==t2)
{
ans+=c*t1*k;
if(ans<=w&&ans>=) return true;
else return false;
}
LL x1=;
int a1=t1-;
while(a1--)
{
x1*=;
}
ans+=(x2-x1+)*t1*k;
LL x3=;
int a2=t2;
while(a2--)
{
x3*=;
}
ans+=(x3-m)*t2*k;
for(LL i=x3; i<x1; i*=)
{
t2++;
ans+=(i*-i)*t2*k;
}
if(ans<=w&&ans>=) return true;
else return false; } int main()
{
while(scanf("%I64d%I64d%I64d",&w,&m,&k)!=EOF)
{
LL l=,r=w;
LL ans=;
while(l<=r)
{
LL mid=(l+r)/;
if(ok(mid))
{
ans=mid;
l=mid+;
}
else
r=mid-;
}
printf("%I64d\n",ans);
}
return ;
}
上一篇:Android中log4j的运用


下一篇:B计划