您的位置:首页 > 其它

zoj Treasure Hunt IV

2014-05-06 17:39 363 查看
Treasure Hunt IVTime Limit: 2 Seconds Memory Limit: 65536 KB
Alice is exploring the wonderland, suddenly she fell into a hole, when she woke up, she found there are b - a + 1 treasures labled a from b in front of her.
Alice was very excited but unfortunately not all of the treasures are real, some are fake.
Now we know a treasure labled n is real if and only if [n/1] + [n/2] + ... + [n/k] + ... is even.
Now given 2 integers a and b, your job is to calculate how many real treasures are there.

Input

The input contains multiple cases, each case contains two integers a and b (0 <= a <= b <= 263-1) seperated by a single space. Proceed to the end of file.

Output

Output the total number of real treasure.

Sample Input

0 2
0 10

Sample Output

1
6


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<math.h>
using namespace std;
typedef unsigned  long long LL;

LL solve(LL n)
{
LL m = (LL)sqrt(n*1.0);
LL sum=0;
if(m%2==0) sum = n-m*m;
if(m%2==1) m++;
LL j=m/2;
sum=sum-j+2*j*j;
// sum=sum+2*j*j-j;
return sum;
}
int main()
{
LL n,m;
while(scanf("%llu%llu",&n,&m)>0)
{
n++,m++;
LL ans=solve(n-1);
LL cur =solve(m);
printf("%llu\n",cur-ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: