1336 - Sigma Function
Time Limit: 2 second(s) Memory Limit: 32 MB

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

Output for Sample Input

4

3

10

100

1000

Case 1: 1

Case 2: 5

Case 3: 83

Case 4: 947


Problem Setter: Shahriar Manzoor
Special Thanks: Jane Alam Jan (Solution, Dataset)
思路:他让求的是偶数的个数,所以我们可以求奇数的个数因为从公式中看,如过要为偶数的话其中有一项为偶数就可以了,如果要为奇数的话所有的都要是奇数,目前我们还不知道
那个方向简单,我们可以两方向都考虑下,最后会发现求奇数方案可行。素数中除了2以外全为奇数,如果数中含有2因子,那么(p1)e1+1/(p1-1)肯定为奇数,这个很好证明,如果p1
为其它素数,如果((p1)e1+1-1)/(p1-1)要为奇数那么e1必定为偶数,我们可以用二项展开证明
因为p1为奇数,设p1=2*k+1;将p1代入,
所以要为奇数的话e1必定要是偶数。所以从1,循环到sqrt(n),因为要素数的幂是偶数次那么(除了2的幂可以为奇数可以为偶数),所以判定下(i*i)<=n和2*i*i<=n有多少就行了。
 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<math.h>
6 using namespace std;
7 typedef long long LL;
8 int main(void)
9 {
10 int i,j,k,p,q;
11 LL ans;
12 scanf("%d",&k);
13 int s;
14 for(s=1; s<=k; s++)
15 {
16 scanf("%lld",&ans);
17 LL cnt=0;
18 for(j=1; j<=sqrt(1.0*ans); j++)
19 {
20 LL bns=(LL)j;
21 if(bns*bns<=ans)
22 {
23 cnt++;
24 }
25 if(2*bns*bns<=ans)
26 {
27 cnt++;
28 }
29 }
30 printf("Case %d: ",s);
31 printf("%lld\n",ans-cnt);
32 }
33 return 0;
34 }

复杂度O(sqrt(n));

1336 - Sigma Function的更多相关文章

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

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

  2. 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+ ...

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

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

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

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

  5. LightOJ 1336 - Sigma Function

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

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

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

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

  8. LightOJ1336 Sigma Function —— 质因子分解、约数和为偶数

    题目链接:https://vjudge.net/problem/LightOJ-1336 1336 - Sigma Function    PDF (English) Statistics Forum ...

  9. 1336 - Sigma Functio

    1336 - Sigma Function Sigma function is an interesting function in Number Theory. It is denoted by t ...

随机推荐

  1. 6 — springboot中设置默认首页 -没屁用

    1.页面在static目录中时 2).测试 2.页面在templates模板引擎中时 1).这种需要导入相应的启动器 <dependency> <groupId>org.spr ...

  2. 为构建大型复杂系统而生的微服务框架 Erda Infra

    作者|宋瑞国(尘醉) 来源|尔达 Erda 公众号 ​ 导读:Erda Infra 微服务框架是从 Erda 项目演进而来,并且完全开源.Erda 基于 Erda Infra 框架完成了大型复杂项目的 ...

  3. Gradle—Android配置详解

    参考[1]彻底弄明白Gradle相关配置       [2]Android Studio gradle配置详解

  4. 100个Shell脚本——【脚本5】数字求和

    [脚本5]数字求和 编写shell脚本,要求输入一个数字,然后计算出从1到输入数字的和,要求,如果输入的数字小于1,则重新输入,直到输入正确的数字为止,示例: 一.脚本 #!/bin/bash whi ...

  5. 文件管理与XMl、JSON解析

    1.使用内部存储器 你可以直接保存文件在设备的内部存储.默认情况下,文件保存在你的应用程序的内部存储,其他应用程序或用户不能访问.当用户卸载你的应用城西是,这些文件被删除. (一)在内部存储创建并写入 ...

  6. mysql 执行报错:Error querying database. Cause: java.sql.SQLSyntaxErrorException:which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

    1.这个错误发生在mysql 5.7 版本及以上版本会出现的问题: mysql 5.7版本默认的sql配置是:sql_mode="ONLY_FULL_GROUP_BY",这个配置严 ...

  7. 【Java】【设计模式】单例设计模式

    思想: 为了避免其他程序过多建立该类对象,先禁止其他程序建立该类对象 为了让其他程序可以访问到该类对象,只好在本类中自定义一个对象 为了方便其他程序对自定义对象的访问,可以对外提供一些访问方式 代码体 ...

  8. axios使用步骤详解(附代码)

    Axios是一个基于Promise的 HTTP 库,可以用在浏览器和node.js 中,因为尤大大的推荐,axios也变得越来越流行.最近项目中使用axios也遇到了一些问题,就借此机会总结一下,如有 ...

  9. python中numpy库ndarray多维数组的的运算:np.abs(x)、np.sqrt(x)、np.modf(x)等

    numpy库提供非常便捷的数组运算,方便数据的处理. 1.数组与标量之间可直接进行运算 In [45]: aOut[45]:array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ ...

  10. Non-terminating decimal expansion; no exact representable decimal result.

    Non-terminating decimal expansion; no exact representable decimal result.  翻译为:非终止十进制扩展; 没有确切的可表示的小数 ...