码迷,mamicode.com
首页 > 其他好文 > 详细

zoj Treasure Hunt IV

时间:2014-05-06 18:08:39      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   color   

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

 

bubuko.com,布布扣
 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 }
bubuko.com,布布扣

 

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

zoj Treasure Hunt IV

标签:style   blog   class   code   java   color   

原文地址:http://www.cnblogs.com/tom987690183/p/3712067.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!