HDU 4279 Number(数论)
2014-12-13 22:44
337 查看
题目:
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
Simple Input:
2
1 1
1 10
Simple Output:
0
4
Hint:For the second case, the real numbers are 6,8,9,10
数论基础理论:欧拉函数
φ函数的值 通式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是不为0的整数。φ(1)=1(唯一和1互质的数(小于等于1)就是1本身)。 (注意:每种质因数只一个。比如12=2*2*3那么φ(12)=12*(1-1/2)*(1-1/3)=4
若n是质数p的k次幂,φ(n)=p^k-p^(k-1)=(p-1)p^(k-1),因为除了p的倍数外,其他数都跟n互质。
设n为正整数,以 φ(n)表示不超过n且与n互
素的正整数的个数,称为n的欧拉函数值,这里函数
φ:N→N,n→φ(n)称为欧拉函数。
欧拉函数是积性函数——若m,n互质,φ(mn)=φ(m)φ(n)。
特殊性质:当n为奇数时,φ(2n)=φ(n), 证明与上述类似。
题目分析:这里用到一个结论:欧拉函数在n>2时,值都为偶数。
我们设f(x)=x-约数个数-互质数个数+1。
当x=1或2时,f(x)=0.
当x>2时,
若x为平方数,f(x)=x-奇-偶+1,f若(x)为奇数,则x必为奇数;
若x不为平方数,f(x)=x-偶-偶+1,若f(x)为奇数,则x必为偶数。
F(x)的值为[3,x]中,其值为奇数平方数+偶数非平方数的个数和,即偶数个数-偶数^2的个数+奇数^2的个数。
而偶数个数为 x/2-1,-1是为了把2减掉。偶数^2个数为 sqrt(x)/2,奇数^2个数为 ( sqrt(x)-(sqrt(x)/2) )-1,这里-1是为了把1减掉。
这题巨坑啊,用C++提交11次wa,用相同的代码G++一次就过,无语了。。。
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
Simple Input:
2
1 1
1 10
Simple Output:
0
4
Hint:For the second case, the real numbers are 6,8,9,10
数论基础理论:欧拉函数
φ函数的值 通式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是不为0的整数。φ(1)=1(唯一和1互质的数(小于等于1)就是1本身)。 (注意:每种质因数只一个。比如12=2*2*3那么φ(12)=12*(1-1/2)*(1-1/3)=4
若n是质数p的k次幂,φ(n)=p^k-p^(k-1)=(p-1)p^(k-1),因为除了p的倍数外,其他数都跟n互质。
设n为正整数,以 φ(n)表示不超过n且与n互
素的正整数的个数,称为n的欧拉函数值,这里函数
φ:N→N,n→φ(n)称为欧拉函数。
欧拉函数是积性函数——若m,n互质,φ(mn)=φ(m)φ(n)。
特殊性质:当n为奇数时,φ(2n)=φ(n), 证明与上述类似。
题目分析:这里用到一个结论:欧拉函数在n>2时,值都为偶数。
我们设f(x)=x-约数个数-互质数个数+1。
当x=1或2时,f(x)=0.
当x>2时,
若x为平方数,f(x)=x-奇-偶+1,f若(x)为奇数,则x必为奇数;
若x不为平方数,f(x)=x-偶-偶+1,若f(x)为奇数,则x必为偶数。
F(x)的值为[3,x]中,其值为奇数平方数+偶数非平方数的个数和,即偶数个数-偶数^2的个数+奇数^2的个数。
而偶数个数为 x/2-1,-1是为了把2减掉。偶数^2个数为 sqrt(x)/2,奇数^2个数为 ( sqrt(x)-(sqrt(x)/2) )-1,这里-1是为了把1减掉。
这题巨坑啊,用C++提交11次wa,用相同的代码G++一次就过,无语了。。。
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; long long f(long long x)//计算小于等于n的real number的个数 { if(x<=4) return 0; long long t=(long long)sqrt(x); long long ans=(x-4)/2;//大于4的偶数的个数 if(t%2==0) return ans; else return ans+1; } //大于4,而且不是偶数的平方数的偶数是real number //奇数的平方的奇数是real number int main() { int T; long long n,m; scanf("%d",&T); while(T--) { scanf("%I64d%I64d",&n,&m); long long res; res=f(m)-f(n-1); printf("%I64d\n",res); } return 0; }
相关文章推荐
- HDU 4279 Number(2012天津网络游戏---数论分析题)
- hdu 4279 Number 2012天津网络赛 数论 分析
- HDU 4279 Number (数论,数学)
- HDU 4279 Number(2012年天津网络赛---数论分析题)
- HDU 4279 2012网络赛Number(数论 欧拉函数结论约数个数)
- HDU 1492 The number of divisors(约数) about Humble Numbers(数论题目要知道定理呀....)
- hdu 2854 Central Meridian Number--数论--暴力--推导
- 【原创】【数论】HDU 2462 The Luckiest number
- 数论基础定理及其应用(hdu 2685 I won't tell you this is about number theory, hdu 2582 f(n),hdu 1792 A New Chan)
- hdu 3816 To Be NUMBER ONE 一道数论 主要是思路
- HDU 4279 Number [数论+简证]
- HDU 4279 Number(数学题,找规律)
- HDU 4279 Number(找规律)
- HDU1492-The number of divisors(约数) about Humble Numbers-数论(计数问题)
- HDU 4279 Number [数学?]
- HDU——4279(2012天津区域赛,数论相关的问题)
- hdu 4279 Number
- hdu 3826 Squarefree number 数论
- HDU 4279 Number (打表找规律)
- hdu 4279 Number