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 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

一开始还考虑用欧拉定理算因子和什么的。。。然后看到数据范围。。。噗。。显然不能那样做。。。所以一开始看清楚数据范围是很重要的。  

这个数据范围应该就是找规律了。。。。结果试着找了下。。。果然有规律hhhhh需要注意的是要分奇偶。。。如果是偶数可能会多算。。。因为这个wa了一发。。。

 1 /*************************************************************************
 2     > File Name: code/zoj/3629.cpp
 3     > Author: 111qqz
 4     > Email: [email protected]
 5     > Created Time: 2015年10月24日 星期六 20时07分02秒
 6  ************************************************************************/
 7
 8 #include<iostream>
 9 #include<iomanip>
10 #include<cstdio>
11 #include<algorithm>
12 #include<cmath>
13 #include<queue>
14 #include<vector>
15 #include<stack>
16 #include<cctype>
17
18 #define yn hez111qqz
19 #define j1 cute111qqz
20 #define ms(a,x) memset(a,x,sizeof(a))
21 using namespace std;
22 const int dx4[4]={1,0,0,-1};
23 const int dy4[4]={0,-1,1,0};
24 typedef long long LL;
25 typedef double DB;
26 const int inf = 0x3f3f3f3f;
27 LL a,b;
28 void pre()
29 {
30     int sum =  1;
31     for ( int i =1; i <= 300 ; i++)
32     {
33     int res = 0 ;
34     for ( int j = 1 ; j <= i ; j++)
35         res = res + i/j;
36     if (res%2==0)
37     {
38         sum++;
39         cout<<"i:"<<i<<endl;
40     }
41
42     }
43
44     printf(" sum: %d\n",sum);
45
46 }
47
48 LL cal( LL n) //计算0到n有多少个数满足
49 {
50     if(n==0) return 1;
51     if (n<0) return 0;
52
53     LL res = 0 ;
54     LL sn = sqrt(n);
55     LL k = sn/2 + 1; //k为等差数列的项数,第k项为4k-3
56
57      res = (2*k-1)*k;
58      if (sn%2==0)
59     {
60     res = res -(4*k-3);
61     res = res+n-(2*k-2)*(2*k-2)+1;
62     }
63
64   //  cout<<"k:"<<k<<" n:"<<n<<" res:"<<res<<endl;
65     return res;
66
67 }
68 int main()
69 {
70   #ifndef  ONLINE_JUDGE
71    freopen("in.txt","r",stdin);
72   #endif
73
74    //pre();
75    while (scanf("%lld %lld",&a,&b)!=EOF)
76     {
77     printf("%lld\n",cal(b)-cal(a-1));
78     }
79
80
81  #ifndef ONLINE_JUDGE
82   fclose(stdin);
83   #endif
84     return 0;
85 }

时间: 2024-11-05 12:20:30

zoj 3629 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 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 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

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)

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

组队赛#1 解题总结 ZOJ 3798 Abs Problem (找规律+打表)

Abs Problem Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Alice and Bob is playing a game, and this time the game is all about the absolute value! Alice has N different positive integers, and each number is not greater than N.

ZOJ 3829 Known Notation --贪心+找规律

题意:给出一个字符串,有两种操作: 1.插入一个数字  2.交换两个字符   问最少多少步可以把该字符串变为一个后缀表达式(操作符只有*). 解法:仔细观察,发现如果数字够的话根本不用插入,数字够的最低标准为'*'的个数+1,因为最优是 '12*3*..' 这种形式,所以先判断够不够,不够就补,然后从左往右扫一遍,如果某个时刻Star+1>Num,那么从开始到这一段是不合法的,要把那个'*'与后面的一个数字交换,此时Star--,Num++.然后步数++.这样得出的结果就是最后的最小步数. 脑子