hdu4279 数论(找规律)

Number

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

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.
打出数据,找规律。东北赛的时候也是一道数论,找规律,就是简单的输入两个数字m和n,然后输出乘积~~
View Code
 1 #include<cmath>
 2 #include<cstdio>
 3 #include<iostream>
 4 using namespace std;
 5 int f[20]={0,0,0,0,0,0,1,1,2,3,4,4,5};
 6 __int64 get(__int64 x)
 7 {
 8     if(x<=12) return f[x];
 9     __int64 tmp=x/2;
10     __int64 now=(__int64)sqrt(1.0*x);
11     if(now&1) tmp-=1;
12     else tmp-=2;
13     return tmp;
14 }
15 int main()
16 {
17     __int64 a,b,t;
18     scanf("%I64d",&t);
19     while(t--)
20     {
21         scanf("%I64d%I64d",&a,&b);
22         printf("%I64d\n",get(b)-get(a-1));
23     }
24 }

 

posted @ 2012-09-12 18:36  _sunshine  阅读(595)  评论(0编辑  收藏  举报