hdu4279 Number

Number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5661    Accepted Submission(s): 1329


 

Problem Description

  Here are two numbers A and B (0 < A <= B). If B cannot be divisible by A, and A and B are not co-prime numbers, we define A as a special number of B.
  For each x, f(x) equals to the amount of x’s special numbers.
  For example, f(6)=1, because 6 only have one special number which is 4. And f(12)=3, its special numbers are 8,9,10.
  When f(x) is odd, we consider x as a real number.
  Now given 2 integers x and y, your job is to calculate how many real numbers are between them.

 

Input

  In the first line there is an integer T (T <= 2000), indicates the number of test cases. Then T line follows, each line contains two integers x and y (1 <= x <= y <= 2^63-1) separated by a single space.

 

Output

  Output the total number of real numbers.

 

Sample Input

 

2 1 1 1 10

 

Sample Output

 
0 4

Hint

For the second case, the real numbers are 6,8,9,10.  

Source

2012 ACM/ICPC Asia Regional Tianjin Online

 

Recommend

liuyiding   |   We have carefully selected several similar problems for you:  4267 4268 4269 4270 4271 

题解:

神奇。

orz

最后化简出来的结果为F(x)=x/2-1+(sqrt(x)%2? 0:-1)

 代码:

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#define ll long long
 
using namespace std;
 
 
ll Sqrt(ll l,ll r,ll a) {
    ll mid=(l+r)/2;
    if(l>r)
        return r;
    if(a/mid>mid)
        return Sqrt(mid+1,r,a);
    else if(a/mid<mid)
        return Sqrt(l,mid-1,a);
    else
        return mid;
}
 
ll solve(ll r) {
    if(r<6)return 0;
    return r/2-2+(ll)Sqrt(1,r,r)%2;;
}
 
int main() {
    int t;
    cin>>t;
    while(t--) {
        ll l,r;
        scanf("%I64d%I64d",&l,&r);
        printf("%I64d\n",solve(r)-solve(l-1));
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41510496/article/details/81071719