hdu4279

/*
分析:
    显然的打表找规律。
    打表后可以发现(用0表示该位置的数不是real number,1表示是)串为:
    00000 1个“10”+111 2个“01”+000 3个“10”+111 4个“01”+000...
    然后答案推一下就出来了。

                                                              2013-10-15
*/






#include"iostream"
#include"cstdio"
#include"cstring"
using namespace std;
const unsigned __int64 limit=3037000498;

unsigned __int64 solve(unsigned __int64 x)
{
	unsigned __int64 ans,low,mid,up,temp;
	low=1;up=limit;
	while(low<=up)
	{
		mid=(low+up)>>1;
		temp=mid*mid+4*mid;
		if(temp<=x)	low=mid+1;
		else		up=mid-1;
	}
	low--;
	ans=low*(low+1)/2 + (low/2 + low%2)*3;
	temp=x-(low*low+4*low);
	if(!temp)	return ans;
	if(temp<=(low+1)*2)
	{
		if((low+1)%2)	ans+=temp/2 + temp%2;
		else			ans+=(temp-1)/2 + (temp-1)%2;
	}
	else
	{
		ans+=low+1;
		if((low+1)%2)	ans+=temp-(low+1)*2;
	}
	return ans;
}
int main()
{
	int T;
	unsigned __int64 a,b,ans[2];
	cin>>T;
	while(T--)
	{
		scanf("%I64u%I64u",&a,&b);
		if(b<=5)	{printf("0\n");continue;}
		if(a<=6)a=0;
		else	a-=6;
		b-=5;

		ans[0]=solve(a);
		ans[1]=solve(b);

		printf("%I64u\n",ans[1]-ans[0]);
	}
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值