HDU 4279 Number-------找规律题

时间:2023-03-09 04:30:20
HDU 4279 Number-------找规律题

Number

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

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
4
这道题,同样的没有思路的题目。
有的人说,1000ms,题目复杂,就想到是找规律了。这规律.....。
1->x : ans
            1-1:0
            1-2:0
            1-3:0
            1-4:0
            1-5:0//x小于等于5之前都是0。5/2-2 = 0
            1-6:1//x是某个数的平方和,且k为偶数。则不变 6/2-2 = 1;
            1-7:1//x是某个数的平方和,且k为偶数。则不变 7/2-2 = 1;
            1-8:2    
            1-9:3//x是某个数k的平方和,且k为奇数。加1  9/3-2 + 1 = 3;
            1-10:4
            1-11:4
            1-12:5
            1-13:5
            1-14:6//x是某个数k的平方和,且k为奇数。加1  14/2-2 + 1 = 6;
            1-15:6
            1-16:6//x是某个数k的平方和,且k为偶数。则不变  16/2-2 = 6;
            1-17:6
            1-18:6
            1-19:7
            1-20:8
            1-21:8
            1-22:9
            1-23:9
            1-24:10
            1-25:11//x是某个数k的平方和,且k为奇数。加1   25/2 -2 + 1 = 11;
            1-26:12
还有考虑区间的问题求的是[n,m]=[1,m]-[1,n-1];
 /*
我只能说,以后遇到复杂度高,
时间小的题目
找规律是一种切入方式 */ #include<stdio.h>
#include<math.h>
#include<stdlib.h> __int64 make_ini(__int64 num)
{
__int64 tmp=num;
if(num<)
return ;
tmp=(num>>)-;
num=(__int64)sqrt(num*1.0);
if(num%==)
tmp++;
return tmp;
} int main()
{
__int64 T,n,m;
while(scanf("%I64d",&T)>)
{
while(T--)
{
scanf("%I64d%I64d",&n,&m);
printf("%I64d\n",make_ini(m)-make_ini(n-));
}
return ;
}
return ;
}