题目连接:http://acm.fzu.edu.cn/problem.php?pid=1988
这个题的关键在于计算G(x)
G(x)的计算方法很奇特,我现在也不能证明
在计算出G(x)之后我们就可以使用二分来寻找答案了
我的代码:
__int64 Count(__int64 n)
{
__int64 i;
__int64 ans=0;
__int64 m=(int)sqrt((double)(n));
for(i=1;i<=m;i++)
{
ans+=n/i;
}
return (ans<<1)-m*m;
}
int main()
{
__int64 m,l,r,mid,t,T=1;
bool flag;
scanf("%I64d",&t);
while(t--)
{
flag=true;
scanf("%I64d",&m);
l=1,r=55592640;
while(l<=r)
{
mid=(l+r)>>1;
__int64 temp=Count(mid);
if(temp>m)
r=mid-1;
else if(temp<m)
l=mid+1;
else
{
flag=false;
printf("Case %I64d: %I64d/n",T++,mid);
break;
}
}
if(flag)
printf("Case %I64d: impossible!/n",T++);
}
return 0;
}