Light OJ 1336 Sigma Function(因子和)
来源:互联网 发布:画画的软件 编辑:程序博客网 时间:2024/05/19 00:54
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*平方数 包含了)
- Light OJ 1336 Sigma Function(因子和)
- Sigma Function (因子和)
- Lightoj1336——Sigma Function(因子和)
- Light Oj 1098 A New Function 因子和
- Light OJ1336 Sigma Function
- LightOJ 1336 Sigma Function(1--n中所有因子和为偶数的数字个数)
- LightOj 1336 Sigma Function(打表找规律)
- lightOJ 1336 Sigma Function
- LightOJ 1336- Sigma Function
- LightOJ 1336 Sigma Function
- LightOJ 1336 Sigma Function
- LightOj 1336(Sigma Function)
- LightOJ 1336 Sigma Function
- Sigma Function LightOJ 1336
- 20160317 Uva11395 Sigma Function(素因子分解+各种公式+筛数)
- LightOJ1336 Sigma Function 素因子分解深入理解
- C - Sigma Function(LightOJ 1336)
- lightoj 1336 - Sigma Function 【数学】
- <fmt:formatDate>标签
- addEventListener调用传参函数的方法
- javascript闭包之函数重载的实现
- 正则表达式入门
- C++虚函数和纯虚函数示例
- Light OJ 1336 Sigma Function(因子和)
- android跳转界面
- 端口号的分类
- 6/29作业:Object类
- BZOJ 1588: [HNOI2002]营业额统计
- 关于protected修饰符
- 博客海鲜面
- GO 通过反射修改有共同字段的不同结构体变量
- 关于iOS中延迟执行的几种方法