Sigma Function
来源:互联网 发布:域名怎么绑定自己电脑 编辑:程序博客网 时间:2024/05/07 13:17
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 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).
For each case, print the case number and the result.
4
3
10
100
1000
Case 1: 1
Case 2: 5
Case 3: 83
Case 4: 947
题目大意:求1到n之间的数因子和是偶数有几个对于任意一个x, 都有x = p1^a1*p2^a2*...*pn^an;所以x的因子和 f(x)= (1+p1+p1^2+p1^3+...+p1^a1)*(1+p2+p2^2+...+p2^a2)*...*(1+pn+pn^2+...+pn^an);因为偶数乘偶数是偶数,偶数乘奇数还是偶数,只有奇数乘奇数是奇数,所以我们必须让每一个小括号都是奇数。最后我们减去奇数项就只剩偶数项了1,然后我们发现当x只有2这一个素因子时,再加上一个1一定是奇数。2, 素数中只有2一个偶数,所以其他素数都是奇数,偶数个奇数想加就是偶数,再加一个1就又会变成偶数,所以p^a(a必须是偶数)x^2的每一个p^a(a一定会是偶数,因为是两个x相乘,所以就是两个a相加,不管是奇数加奇数,还是偶数加偶数都会是偶数)3,x^2因子和是偶数了,那么2*x^2的因子和也一定是偶数。因为就算再多一个2也没关系,最后还是会加上一个1还是奇数。所以最后只用减去2^x,x^2和2*x^2,x^2和2*x^2又包含2^x,所用只用减去x^2和2*x^2.
#include<stdio.h>#include<iostream>#include<math.h>#include<string.h>#include<algorithm>using namespace std;#define ll long longint main(){ int t; scanf("%d",&t); int g=0; while(t--) { ++g; ll n; scanf("%lld",&n); ll sum=n; sum-=(int)sqrt(n); sum-=(int)sqrt(n/2); printf("Case %d: %lld\n",g,sum); }}
- Sigma Function
- Sigma Function
- Sigma Function
- Sigma Function
- lightOJ 1336 Sigma Function
- LightOJ 1336- Sigma Function
- Light OJ1336 Sigma Function
- LightOJ 1336 Sigma Function
- LightOJ 1336 Sigma Function
- Sigma Function (因子和)
- Sigma Function(算数技巧)
- LightOj 1336(Sigma Function)
- LightOJ 1336 Sigma Function
- Sigma Function LightOJ
- Sigma Function LightOJ 1336
- Sigma Function LightOJ
- D Sigma Function
- C - Sigma Function(LightOJ 1336)
- a标签提交
- C# 反射 自动设置 两个类的 字段相同的数据
- C++中的static关键字的总结
- 栈和队列的面试题(五)---判断元素出栈、入栈顺序的合法性
- GO语言bit集合
- Sigma Function
- MQTT-SN协议简要介绍
- Android新特性之RecyclerView和CardView联合使用
- Bootstrap关闭弹出窗导致另一个弹出窗滚动条消失的解决办法
- Java图片的序列化和反序列化以及格式转换如tif等
- 决策树之ID3算法
- char* p 和 char p[]区别及应用
- Codeforces 797C Minimal string【贪心】
- google play X509TrustManager提示