您的位置:首页 > 其它

FZU 1988 二分+数论

2011-04-27 17:00 381 查看
题目连接:http://acm.fzu.edu.cn/problem.php?pid=1988

这个题的关键在于计算G(x)

G(x)的计算方法很奇特,我现在也不能证明

在计算出G(x)之后我们就可以使用二分来寻找答案了

我的代码:

#include<stdio.h>
#include<math.h>

__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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: