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. vs推送git失败,修改git下config的Log

    一开始写完程序套推送到Git中,然后就来了一下,下面的异常: 异常1 发布到远程存储库时遇到错误: Git failed with a fatal error. fatal: HttpRequestE ...

  2. GitHub进阶之利用Git远程仓库篇

    #在上一篇文章,相信大家对GitHub已经有了一个基础的理解 接下来我们来学习一下如何利用git来远程仓库 一,git是什么 git:一个免费的开源版本控制软件 用途:利用Git管理GitHub上的代 ...

  3. [bzoj4827] [洛谷P3723] [Hnoi2017] 礼物

    Description 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手 环,一个留给自己,一 个送给她.每个手环上各有 n 个装饰物,并且每个装饰物都有一定的亮度.但是 ...

  4. C++ 一篇搞懂多态的实现原理

    虚函数和多态 01 虚函数 在类的定义中,前面有 virtual 关键字的成员函数称为虚函数: virtual 关键字只用在类定义里的函数声明中,写函数体时不用. class Base { virtu ...

  5. 谈谈模型融合之三 —— GBDT

    前言 本来应该是年后就要写的一篇博客,因为考完试后忙了一段时间课设和实验,然后回家后又在摸鱼,就一直没开动.趁着这段时间只能呆在家里来把这些博客补上.在之前的文章中介绍了 Random Forest ...

  6. HTTP负责均衡模块(HTTP Upstream)

    这个模块为后端的服务器提供简单的负载均衡(轮询(round-robin)和连接IP(client IP))如下例: upstream backend  {  server backend1.examp ...

  7. Linux 常用工具openssh之ssh-add

    前言 ssh-add命令是把专用密钥添加到ssh-agent的高速缓存中,从而提高ssh的认证速度 语法 ssh-add [-cDdLlXx] [-t life] [file ...] 选项 -D:删 ...

  8. IDEA更换banner(娱乐专用)

    1.佛祖保佑 永无bug _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / ...

  9. Redis搭建哨兵模式

    一 安装Redis 1. 从https://redis.io/download redis官网下载二进制包安装 例如:wget http://download.redis.io/releases/re ...

  10. 浏览器无法进入GitHub(已解决)

    时间:2020/1/22 今天突然chrome登不上GitHub,一直出现响应时间过长的问题,如下: 开始还以为是GitHub服务器出问题了(虽然概率很小.....),但这种情况一直持续了几个小时,我 ...