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.
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; }
相关文章推荐
- ZOJ 3629 Treasure Hunt IV
- 【数学规律】-ZOJ-3629-Treasure Hunt IV
- ZOJ ——3629 Treasure Hunt IV
- zoj 3629 Treasure Hunt IV
- ZOJ3629 Treasure Hunt IV(找到规律,按公式)
- ZOJ-#3629 Treasure Hunt IV(找规律)
- ZOJ Treasure Hunt IV
- zoj 3629 Treasure Hunt IV(找规律)
- zoj 3629 Treasure Hunt IV 打表找规律
- zoj 3629 Treasure Hunt IV
- ZOJ3629 Treasure Hunt IV(找规律,推公式)
- ZOJ 3626 Treasure Hunt I (树形dp)
- zoj 3626 Treasure Hunt I(树形DP+分组背包)
- ZOJ Problem Set - 3626 Treasure Hunt I
- ZOJ 3626 Treasure Hunt I(树形dp)
- zoj 3626 Treasure Hunt I
- ZOJ 3626 —— Treasure Hunt I(树形DP + 背包)
- zoj 3268 Treasure Hunt III (dp)
- ZOJ 4772 Treasure Hunt I 树形DP(背包) && hdu The Ghost Blows Light 树形DP(背包)
- [zoj 3626]Treasure Hunt I 树DP