• Sigma Function 数学 因子求和


    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

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<sstream>
    #include<algorithm>
    #include<queue>
    #include<vector>
    #include<cmath>
    #include<map>
    #include<stack>
    #include<set>
    #include<fstream>
    #include<memory>
    #include<list>
    #include<string>
    using namespace std;
    typedef long long LL;
    typedef unsigned long long ULL;
    #define MAXN  1000010
    #define LLL 1000000000
    #define INF 1000000009
    /*
    给一个公式,将一个数表示为所有素因子等比数列 求前e个 的乘积
    求小于n的数中为奇数的个数
    数据很大不能打表。。
    当p为偶数 ,p的次方为偶数,加上p的0次方 最后得出奇数不成立
    当P为奇数,P的次方为奇数,要有偶数个奇数相加才能得出偶数,要求e为奇数
    当所有的 p和e中总是存在任何一个不为奇数的时候,结果为奇数
    e为偶数 平方数  后面乘某些数 后面的数字是2的几次方的时候仍然成立 (2是唯一的素偶数)
    所有个数为 平方数||2*平方数
    */
    int main()
    {
        LL T,n;
        scanf("%lld", &T);
        for(LL cas=1;cas<=T;cas++)
        {
            scanf("%lld", &n);
            LL t1 = sqrt(n*1.0);
            LL t2 = sqrt(n*0.5);
            printf("Case %lld: %lld
    ",cas, n - t1 - t2);
        }
        return 0;
    }
  • 相关阅读:
    memcached与redis 对比
    Java中的成员初始化顺序和内存分配过程
    mysql inner join,full outer join,left join,right jion
    事务 相关概念理解
    最简单的重试机制
    垃圾脚本黑我linux服务器
    趣解curl
    面试题
    Java中OutOfMemoryError(内存溢出)的三种情况及解决办法
    PermGen space
  • 原文地址:https://www.cnblogs.com/joeylee97/p/6829730.html
Copyright © 2020-2023  润新知