Treasure Hunt IV title to find the law

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

************************************************* ************************************************** ************************************************** ******
by calculating we will find only in the interval [0, 1), [4,9), [16, 25) ...... it is satisfied that Italy
*********** ************************************************** ************************************************** *******************************************
 1 #include<iostream>
 2 #include<string>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<queue>
 6 #include<cmath>
 7 using namespace std;
 8 typedef long long ll;
 9 const double eps=1e-6;
10 ll solve(ll n)
11 {
12      if (n == -1) return 0;
13     ll r = (ll)sqrt((double) n + . 1 + EPS);
 14      IF (R & lt & . 1 ) {
 15          R & lt = (R & lt + . 1 ) >> . 1 ;
 16          return ((R & lt << . 1 ) - . 1 ) * R & lt;
 . 17      }
 18 is      the else {
 . 19          return n-- R & lt + R & lt * (R & lt >> . 1 ) * (R & lt - . 1 ) + . 1 ; // subtracting the number of unnecessary between two sections 
20 is      }
 21 is  }
 22 is  int main ()
 23 is  {
 24      LL a, B;
 25     while(~scanf("%lld %lld",&a,&b))
26     {
27         ll ans=solve(b)-solve(a-1);
28         printf("%lld\n",ans);
29     }
30     return 0;
31 }
View Code

 

Reproduced in: https: //www.cnblogs.com/sdau--codeants/p/3440129.html

Guess you like

Origin blog.csdn.net/weixin_33835690/article/details/93432858