题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3629
题意:问某个区间内这样的数 n 有几个,n 满足: [n/1] +[n/2] + ... + [n/n] 是偶数
思路:打出100的表就可以找出规律,发现0,4-8,16-24,36-48,64-80都是可以的,所以推出n^2~(n+1)^2 (n是偶数)的区间都是可以的。
代码:
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define eps 1e-7
#define fuck(x) cout<<"<"<<x<<">"<<endl
#define fi first
#define se second
#define pb push_back
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const double PI = acos(-1.0);
const LL INFLL = 0x3f3f3f3f3f3f3f3fll;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
ull a,b;
ull f(ull n){
if (n==-1) return 0;
ull ans=0;
ull x=sqrt(n);
if (x&1){
ans+=((x+1)/2)*x;
}
else {
ans+=(n-x*x+1);
ans+=(x/2)*(x-1);
}
return ans;
}
int main() {
while (cin>>a>>b){
cout<<f(b)-f(a-1)<<endl;
}
return 0;
}