http://acm.hdu.edu.cn/showproblem.php?pid=4279
找规律,无语,看了解题报告,还能这样找规律,本以为有什么神奇的解法。不敢做题。
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
int f[20]={0,0,0,0,0,0,1,1,2,3,4,4,5};
__int64 get(__int64 x)
{
if(x<=12) return f[x];
__int64 tmp=x/2;
__int64 now=(__int64)sqrt(1.0*x);
if(now&1) tmp-=1;
else tmp-=2;
return tmp;
}
int main()
{
__int64 a,b,t;
scanf("%I64d",&t);
while(t--)
{
scanf("%I64d%I64d",&a,&b);
printf("%I64d\n",get(b)-get(a-1));
}
return 0;
}