解题思路
找规律+前缀和
$x=y^2-z^2=(y+z)(y-z)$
令$A=y+z$,$B=y-z$
则有 $A-B=2z$,即相减为偶数
那么A、B的可能只有A、B均为偶数,A、B均为奇数两种形式
若A、B均为偶数,则x一定为4的倍数
若A、B均为奇数,则x可以为任意奇数
AC代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int get_num(int x)
{
int res=0;
res+=(x+1)/2; //odd
res+=x/4; //4
return res;
}
int main()
{
int l,r;
cin>>l>>r;
cout<<get_num(r)-get_num(l-1);
return 0;
}