码迷,mamicode.com
首页 > 其他好文 > 详细

LightOJ - 1336 - Sigma Function(质数分解)

时间:2019-11-13 01:12:41      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:sig   main   链接   iostream   ios   space   you   存在   lld   

链接:

https://vjudge.net/problem/LightOJ-1336

题意:

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+p_1^1+p_1^2+...+p_1^{k1})*(1+p_2^1+p_2^2+...+p_2^{k2})...\)
考虑和为奇数情况。
存在素因子2时,(1+2^n)为奇数,则和为奇数。
其他素因子为奇数,奇数乘奇数为奇数,1+偶数为奇数,偶数乘奇数为偶数,则只有素因子的指数为偶数时满足和为奇数。
由此得到其他数都为平方数。或者时平方数*2

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>

using namespace std;
typedef long long LL;
const int INF = 1e9;

const int MAXN = 1e6+10;
const int MOD = 1e9+7;

LL n;

int main()
{
    int t, cnt = 0;
    scanf("%d", &t);
    while(t--)
    {
        printf("Case %d:", ++cnt);
        scanf("%lld", &n);
        LL tmp = n;
        tmp -= (LL)sqrt(n);
        tmp -= (LL)sqrt(n/2);
        printf(" %lld\n", tmp);
    }
    
    return 0;
}

LightOJ - 1336 - Sigma Function(质数分解)

标签:sig   main   链接   iostream   ios   space   you   存在   lld   

原文地址:https://www.cnblogs.com/YDDDD/p/11846273.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!