Sigma Function (找规律?)

来源:互联网 发布:淘宝退换货说明 编辑:程序博客网 时间:2024/05/19 01:07

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 σ.

1、给的数据很大,到1012,所以暴力不行啊。
2、前两题判断素数什么的都是到106就结束了,我考虑了一下只找半行不行= =,当然是不行的。 。 。
3、同时也注意到素数中只有2对应的值是奇数,其它素数一定是奇数,所以对应的函数值是偶数,但是我能想到的解决方法还是暴力解决。
4、寻找答案的帮助,发现这好像是一个找规律?反正就是有式子算一下就行,这数学问题真的是。。。
5、解答:

  • 首先因为偶数情况很多,我们来考虑奇数的情况好了(这个下次不能忘!我们可以从反面考虑的啊!)
  • 然后把式子化为1+p1+p21++pe11(1+p2+p22++pe22)1+pk+p2k++pekk
    于是只有2这个因子时一定是奇数,即2n满足条件;
    其它p都是奇数,奇数的次方都是奇数,1也是奇数,因此对其中的一个括号,当e是奇数时括号里的和是偶数,当e是偶数时括号里的和是奇数。只有奇数乘奇数才会是奇数,因此里面的所有除2之外的p对应的ei都是偶数。
  • 然后看别的做法是考虑对n开根号,这样得到的值也就是被开根号后还是整数的数的个数,这些数的e1ek一定都是偶数;再对n/2开根号,因为对因子2来说e是偶数奇数都没有关系,这样就找到了所有对应的函数值是奇数的数的个数。
  • 最后就是nnn/2

6、写完想想感觉好简单。。。然而在做题的时候就是想不到啊啊啊啊,嗯。。。果然还是要多做题(严肃脸)。还有以后做题要注意时间啊时间啊,这两天的效率是越来越低了,这样不行不行不行。
7、最后给出代码,不然感觉我的博客写的太水了= =

#include <cstdio>#include <algorithm>#include <iostream>#include <cstring>#include <queue>#include <cmath>using namespace std;long long int n, ans;int main(){    int T;    while (~scanf("%d", &T)){    int t;    for(t=1; t<=T; t++)    {       cin>>n;       ans=n-int(sqrt(n))-int(sqrt(n*0.5));  //注意这里的int!!!先开始没注意又被自己坑了一次       printf("Case %d: %lld\n", t, ans);    }    }    return 0;}
原创粉丝点击