UVA-11395-因数和为偶数
来源:互联网 发布:php api接口验证 编辑:程序博客网 时间:2024/05/22 06:34
Sigma Function
Description
Sigma function is an interesting function in Number Theory. It is denoted by the Greek letter Sigma (σ). This function actually denotes the sum of all divisors of a number. For example σ(24) = 1+2+3+4+6+8+12+24=60. Sigma of small numbers is easy to find but for large numbers it is very difficult to find in a straight forward way. But mathematicians have discovered a formula to find sigma. If the prime power decomposition of an integer is
Then we can write,
For some n the value of σ(n) is odd and for others it is even. Given a value n, you will have to find how many integers from 1 to n have even value ofσ.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing an integer n (1 ≤ n ≤ 1012).
Output
For each case, print the case number and the result.
Sample Input
4
3
10
100
1000
Sample Output
Case 1: 1
Case 2: 5
Case 3: 83
Case 4: 947
题意:1~n (n:1~1012)中,因子和为偶数的有几个。
题解:My New Blog
因子和 Sum=(p1^0+p1^1….p1^e1)*(p2^0+p2^1…p2^e2)……(pn^0+…pn^en);
=
(p1^0+p1^1….p1^e1),(p2^0+p2^1…p2^e2),……(pn^0+…pn^en)中只要有一个是偶数,因子和sum就为偶数。所以只要找到一个是偶数就可以了。
若pi为偶数,则pi^x(x>0)为偶数,而pi^0=1(1+偶+偶….为奇数)。So,(pi^0+pi^1+…pi^ei)为奇数。所以pi只能是奇数,才能使(pi^0+pi^1+…pi^ei)为偶数。
再看pi^x (若x为奇数,pi^x为奇数(奇*奇*…为奇)),So,(pi^0+pi^1+…pi^ei)为偶数(1+奇+奇…)
所以,对m素因子分解,只要存在一个pi,ei都为奇数的pi^ei,就能使sum为偶数。
然而这么做必定TLE(-。-;)
再想想,1~n中 有多少个数的素因子分解中存在pi^ei(奇^奇)。
3^(2k-1) * (1,2,3,4..n/3) (k>1&&3^(2k-1)<=n)
5^(2k-1) * (1,2,3,4…n/5)
….
prime[i]^(2k-1) * (1,2,3,…n/prime[i]) 能包含所有的解,然而还有好多重复的解。看着有点像容斥定理,但多了个条件。(prime[i]^1,prime[i]^3…容斥有问题)。想了好久,感觉这题好难,不会了。。
不会咋办,换个思路呗!
不过之前还是忍不住暴力了一下 果断TLE。
反过来想,什么时候因子和是奇数呢?
由前面的分析(只要存在一个pi,ei都为奇数的pi^ei,就能使sum为偶数),素因子分解后,全为奇^偶,偶^偶,偶^奇,因子和就是奇数。
2是唯一一个偶素数。(特别的就得拿出来分开考虑。。)
((数^(偶/2)*(数^(偶/2))....)^2,这不是平方数吗!(数指的是奇数||偶数) (包含了数^偶)
所以这些数是 平方数 || 2*平方数 。(想不通的可以拿奇^偶,偶^偶,偶^奇组合,发现全被平方数 || 2*平方数 包含了)
- UVA-11395-因数和为偶数
- LightOJ 1336 Sigma Function(求1~n的因数和为偶数的个数)
- 求一个数因数个数,因数和
- 和为x的最小偶数
- 最大奇因数和
- 因数
- UVa 10879 Code Refactoring (因数分解)
- UVa 10392 Factoring Large Numbers(分解因数)
- uva 11464 偶数矩阵
- UVA 11464 偶数矩阵
- 小于N的自然数为偶数的和----bitwise
- 为奇数和偶数行设置不同的格式
- UVa 11464 EvenParity 偶数矩阵
- UVa 11464 偶数矩阵 枚举
- UVA - 11490 Just Another Problem (因数分解)
- UVA 10892 LCM Cardinality (分解因数+暴力)
- 分解质因数和求因数个数
- 求一个数的因数和
- hdu1176 免费馅饼 DP
- Android学习日记(yzy):Broadcast Receiver的注册和发送
- Android绘制波浪线
- 正态性检验,多元线性和多项式回归,输出具体的回归函数
- Spring Data JPA 一Projections
- UVA-11395-因数和为偶数
- JS定义类的六种方式详解
- 大数据分析与人工智能技术与应用特别训练营7月28日-29日 | 北京
- 基于光流分析的运动目标快速检测与跟踪融合算法
- 网页自动识别移动端js,百度的,感觉挺好用的,兼容比较广
- Java基础(五)数组与算法
- 自定义拦截器
- Codeforces 459E Pashmak and Graph【Dp】
- 第三章 流Stream