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\n", cas, sum);

}

return 0;
}

1336 - Sigma Functio的更多相关文章

  1. 1336 - Sigma Function

    1336 - Sigma Function   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB S ...

  2. 1336 - Sigma Function---LightOj1336

    http://lightoj.com/volume_showproblem.php?problem=1336 题目大意:求1到n之间的数因子和是偶数有几个对于任意一个x, 都有x = p1^a1*p2 ...

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

    链接: https://vjudge.net/problem/LightOJ-1336 题意: Sigma function is an interesting function in Number ...

  4. LightOJ 1336 Sigma Function 算数基本定理

    题目大意:f(n)为n的因子和,给出 n 求 1~n 中f(n)为偶数的个数. 题目思路:算数基本定理: n=p1^e1*p2^e1 …… pn^en (p为素数): f(n)=(1+p1+p1^2+ ...

  5. LightOJ 1336 Sigma Function(数论 整数拆分推论)

    --->题意:给一个函数的定义,F(n)代表n的所有约数之和,并且给出了整数拆分公式以及F(n)的计算方法,对于一个给出的N让我们求1 - N之间有多少个数满足F(x)为偶数的情况,输出这个数. ...

  6. LightOJ - 1336 Sigma Function(约数和+整数拆分)

    题干中给出函数公式: 其中pi为n的每个素因数,ei为其个数.设该函数为F(x),其意义为x的约数之和.问在1-n中有多少x,令F(x)为偶数. 分析:设f(p)为(p^(e+1)-1)/(p-1). ...

  7. LightOJ 1336 - Sigma Function

    原题链接 基础数论中很经典的一道题 题意 给出了σ(n)的计算公式,让你找出整数1-n中有多少对应σ(n)的值是偶数. 思路 观察σ(n)的公式发现,每一个乘项都是 (piei+1 - 1) / (p ...

  8. light oj 1336 sigma function

    常用的化简方法(高中就常用了):     p^(e+1)-1/p-1=             [ p^(e+1) -p + (p-1) ]/ (p-1) = p*(p^e-1)/(p-1) + 1  ...

  9. LightOJ 13361336 - Sigma Function (找规律 + 唯一分解定理)

    http://lightoj.com/volume_showproblem.php?problem=1336 Sigma Function Time Limit:2000MS     Memory L ...

随机推荐

  1. win10内存泄漏怎么办

    我的电脑莫名的内存占用越来越高,但是实际内存很低 查了很多资料 下边是我找到的最有效的方法: 原因:是系统自带的网络数据监控和和Killer网卡的监控程序冲突,导致 非页面缓存无法释放. 解决方法:解 ...

  2. Java 几道常见String面试题

    String s1="abc"; String s2="abc"; System.out.println(s1==s2); System.out.println ...

  3. Webpack实战(四):教教你如何轻松搞定-预处理器(loader)

    前面三节,我主要给大家分享了有关webpack的一些配置的知识点,如何打包js文件,而如果我们遇到其他类型的资源如图片.css.字体font等等,我们该如何处理呢?今天会介绍预处理器(loader), ...

  4. Nginx作为web静态资源服务器——防盗链

    ​ 基于http_refer防盗链配置模块 Syntax:valid_referers none | blocked | server_names | string ...; Default:—— C ...

  5. NumPy排序

    numpy.sort()函数 该函数提供了多种排序功能,支持归并排序,堆排序,快速排序等多种排序算法 使用numpy.sort()方法的格式为: numpy.sort(a,axis,kind,orde ...

  6. mysql 用户操作和授权

    1.查看mysql的版本 mysql -V 2.用户操作 # 创建用户 create user 'username'@'ip地址' identified by '密码'; # 用户重命名 rename ...

  7. 在Navicat新建Oracle表及用户

    1. 打开Navicat,链接Oracle, 连接成功. 2. Ctrl+Q,进入查询,创建表空间. 输入create tablespace test datafile 'D:\Oracle\test ...

  8. 管理2000+Docker镜像,Kolla是如何做到的

    根据 DockerHub 上的数据,整个 Kolla 项目管理的 镜像有 2000 多个,这么多的镜像,是怎么定义,又是如何构建的呢? 简介 我们一直在说的 Kolla,通常情况下泛指,包括了 Kol ...

  9. ASP.NET MVC4 使用UEditor富文本

    原帖:http://user.qzone.qq.com/369175376/infocenter?ptlang=2052     第一步:先到http://ueditor.baidu.com/webs ...

  10. 关于Queries_per_sec 性能计数器

    [问题描述] Queries_per_sec (QPS)是数据库两个比较重要的性能计数器指标.我们经常要求开发告知这个参数,以评估数据库的一个负载情况.下面的这段代码连上服务器,做一个简单的查询: u ...