zoj Treasure Hunt IV

Treasure Hunt IV


Time 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


 1 #include<iostream>
2 #include<stdio.h>
3 #include<cstring>
4 #include<cstdlib>
5 #include<math.h>
6 using namespace std;
7 typedef unsigned long long LL;
8
9 LL solve(LL n)
10 {
11 LL m = (LL)sqrt(n*1.0);
12 LL sum=0;
13 if(m%2==0) sum = n-m*m;
14 if(m%2==1) m++;
15 LL j=m/2;
16 sum=sum-j+2*j*j;
17 // sum=sum+2*j*j-j;
18 return sum;
19 }
20 int main()
21 {
22 LL n,m;
23 while(scanf("%llu%llu",&n,&m)>0)
24 {
25 n++,m++;
26 LL ans=solve(n-1);
27 LL cur =solve(m);
28 printf("%llu\n",cur-ans);
29 }
30 return 0;
31 }

zoj Treasure Hunt IV,布布扣,bubuko.com

时间: 2024-10-15 08:07:23

zoj Treasure Hunt IV的相关文章

zoj 3629 Treasure Hunt IV 打表找规律

H - Treasure Hunt IV Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Description 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

ZOJ3629 Treasure Hunt IV(找规律,推公式)

Treasure Hunt IV Time 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

zoj 3629 Treasure Hunt IV(找规律)

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 fromb in front of her.Alice was very excited but unfortunately not all of the treasures are real, some are fake.Now w

zoj3629 Treasure Hunt IV

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3629 思路:找规律,发现符合要求的数为 [0,1) [4,9) [16,25) [36,49) ---- [n^2 , (n+1)^2) 发现 n^2 到(n+1)^2(n为偶数)前开后闭的区间为符合要求的数,然后发现(n+1)*(n+1)-n*n组成的数列为一个差值为4等差数列,我们需要求区间[a,b]符合要求的数,那么只需要用b前面符合要求的数减去a-1中符

zoj 3626 Treasure Hunt I (树形dp)

题目大意: 给出一棵树,求出从起点开始走m长度最后回到起点,所能得到的宝藏的最大价值. 思路分析: 通过一次dfs可以得到的是子树到根节点的所有距离的最大值. 现在的问题就是他走完一颗子树可以去另外一颗子树. 所以在回溯到根的时候要统计其他子树上互补距离的最大值. dp[i] [j] 表示i为根节点,在i的子树中走j步然后回到i所能拿到的最大价值. 转移方程就是 dp[x][i+2*len]=max(dp[x][i+2*len],dp[v][j]+dp[x][i-j]); v为x的子树的根,le

[zoj 3626]Treasure Hunt I 树DP

<span style="font-family: Arial, Helvetica, Verdana, sans-serif; background-color: rgb(255, 255, 255);">Treasure Hunt I</span> Time Limit: 2 Seconds      Memory Limit: 65536 KB Akiba is a dangerous country since a bloodsucker living

ZOJ 3626 Treasure Hunt I(树形dp)

Treasure Hunt I Time Limit: 2 Seconds      Memory Limit: 65536 KB Akiba is a dangerous country since a bloodsucker living there. Sometimes the bloodsucker will appear and kill everyone who isn't at his hometown. One day, a brave person named CC finds

【树形dp】Treasure Hunt I

[ZOJ3626]Treasure Hunt I Time Limit: 2 Seconds      Memory Limit: 65536 KB Akiba is a dangerous country since a bloodsucker living there. Sometimes the bloodsucker will appear and kill everyone who isn't at his hometown. One day, a brave person named

POJ1066 Treasure Hunt(线段相交)

题目链接: http://poj.org/problem?id=1066 题目描述: Treasure Hunt Description Archeologists from the Antiquities and Curios Museum (ACM) have flown to Egypt to examine the great pyramid of Key-Ops. Using state-of-the-art technology they are able to determine