http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4775
当时比赛的时候没有做出来,隔几天之后再想想发现是个水题呀!原因就是当时虽然也找到规律了,但是没有想好,就一直在哪儿调试……悲剧
规律我都不说了,很容易找到的
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
ll solve(ll n)
{
if(n<0) return 0;
ll ret=(ll)(sqrt(n*1.0)+0.00000001);
ll ans=0;
if(ret%2==0) ans+=n-ret*ret+1,ret--;
ans+=ret*(ret+1)/2;
return ans;
}
int main()
{
ll a,b;
while(scanf("%lld %lld",&a,&b)==2)
{
printf("%lld\n", solve(b) - solve(a-1));
//cout<< solve(b) <<endl;
}
return 0;
}