zoukankan      html  css  js  c++  java
  • 1336

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

    分析:

    对于任意一个x, 都有x = p1^a1*p2^a2*...*pn^an;所以x的所有因子和f(x) = ( 1 + p1 + p1^2+ ...p1^a1)(1 + p2 + p2 ^ 2 + ...p2^a2)...(1 + pn + pn^2 +...pn^an).
    偶数和偶数乘积为偶,偶和奇的乘积为偶,只有奇和奇的乘积为奇,所以我们求出和为奇的然后减去就是偶的了。
    1x只有素因子2时 加上1一定为奇。
    2偶数个奇数相加为偶,只有素因子2为偶数,加上1 为奇数,所以ai需为偶数,所以完全平方数x^2的每一个p^a(a一定会是偶数,因为是两个x相乘,所以就是两个a相加,不管是奇数加奇数,还是偶数加偶数都会是偶数)
    3x^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<cstdio>
    #include<cstring>
    #include<cmath>
    #include<iostream>
    #include<algorithm>
    #include<queue>
    #include<stack>

    using namespace std;
    typedef long long ll;
    const int maxn = 1e7+5;
    const int mod = 1000;

    int quickmi(int a, int b)
    {
    if(b == 0)
    return 1;

    int tmp = quickmi(a, b>>1);

    tmp = tmp * tmp % mod;

    if(b & 1)
    tmp = tmp * (a % mod) % mod;

    return tmp % mod;

    }
    int main(void)
    {
    int T, cas;
    ll n;

    scanf("%d", &T);

    cas = 0;

    while(T--)
    {
    cas++;

    scanf("%lld", &n);

    ll sum;

    sum = n;
    sum -= (int)sqrt(n);
    sum -= (int)sqrt(n/2);


    printf("Case %d: %lld ", cas, sum);

    }

    return 0;
    }

  • 相关阅读:
    HDU 5486 Difference of Clustering 图论
    HDU 5481 Desiderium 动态规划
    hdu 5480 Conturbatio 线段树 单点更新,区间查询最小值
    HDU 5478 Can you find it 随机化 数学
    HDU 5477 A Sweet Journey 水题
    HDU 5476 Explore Track of Point 数学平几
    HDU 5475 An easy problem 线段树
    ZOJ 3829 Known Notation 贪心
    ZOJ 3827 Information Entropy 水题
    zoj 3823 Excavator Contest 构造
  • 原文地址:https://www.cnblogs.com/dll6/p/7700304.html
Copyright © 2011-2022 走看看