Sigma Function

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Description

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

4

3

10

100

1000

Sample Output

Case 1: 1

Case 2: 5

Case 3: 83

Case 4: 947

首先给出题目中的公式的推导过程:

n是一个整数,f(n)代表他的因子的和。假设n=12,对他进行素因子分解可得n=2^2*3。12的因子有1,2,3,4,6,12,和为28。根据题目中的公式:f(n)=(2^3-1)/(2-1)*(3^2-1)/(3-1)=7*4=28。为什么会是这样呢?将因子再进行素因子分解可以发现:1=2^0*3^0 , 2=2^1*3^0 , 3=2^0*3^1 , 4=2^2*3^0 , 6=2^1 *3^1 , 12=2^2*3^1。所以1+2+3+4+6+12=2^0*3^0+2^1*3^0+2^0*3^1+2^2*3^0+2^1 *3^1+2^2*3^1=(2^0+2^1+2^2)*(3^0+3^1)。利用等比数列前n项和公式:(2^3-1)/(2-1)*(3^2-1)/(3-1)=7*4=28。推导完毕。

事实上,这称之为积性函数

解题思路:

题意:

求 1—n 中,有多少个数的因子和是偶数。

题解:

打表找规律。

素因子分解打表计算前n项和判断奇数偶数可以发现如下规律:

只要是2^x,a^2,2*a^2...只有这种数的因子和是奇数。所以,我们直接去重即可。
但是这些直接去重我们会发现减去的这些值有重复的,所以我们要判断下。

i (代表x||a): 0 1 2 3 4 5 6 7 8 9 ......

2^x: 1 2 4 8 16 32 64 128 ......

a^2: 0 1 4 9 16 25 36 49 64 ......

2*a^2: 0 2 8 18 32 50 72 ......

我们可以发现2^x里面有的数,a^2和2*a^2里面都有。

加下划线的字一一对应,加粗的字一一对应。

①2^x和a^2,  当x为偶数时二者出现重复。
②2^x和2*a^2,当x为奇数时,二者出现重复。

所以不需要考虑2^x的个数,直接用n减去a^22*a^2的个数就是我们要的结果。

易知:a^2的个数=sqrt(n),2*a^2的个数=sqrt(n/2)。

那么为什么会是这样呢?给出推导过程:

n=p1^e1*p2^e2...,则f(n)=(p1^(e1+1)-1)/(p1-1))*(p2^(e2+1)-1)/(p2-1))....
且(p1^(e1+1)-1)/(p1-1))=p1^0+p1^1......+p1^e1;
要使得f(n)为奇数,则(p1^(e1+1)-1)/(p1-1)到(pn^(en+1)-1)/(pn-1)都要为奇数;

因为奇数*奇数=奇数,奇数*偶数=偶数;

1)当p=2时,2^(e+1)-1,一定为奇数;
2)当p!=2时,则p为奇数(因为p是素因子),则当e为偶数时(p^(e+1)-1)/(p-1)为奇数。

经转化我们可以发现,2^6=8^2,2^11=2*32^2。也就是平方数和2倍的平方数。
则需要统计1到n中的平方数个数2倍的平方数的个数,得到的为1到n中f(n)为奇数的个数。

#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
typedef long long ll;
int main()
{
int t,cas=;
cin>>t;
while(t--)
{
ll n,a,b;
cin>>n;
a=sqrt(n);
b=sqrt(n/);
printf("Case %d: %lld\n",cas++,n-a-b);
}
return ;
}

LightOJ1336 Sigma Function(约数和为偶数的个数)的更多相关文章

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

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

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

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

  3. LightOJ-1336 Sigma Function 唯一分解定理 巧妙使用sqrt()等算数目

    题目链接:https://cn.vjudge.net/problem/LightOJ-1336 题意 给出一个区间[1, n],求区间内所有数中因数之和为偶数的数目 思路 第二次写这个题 首先想到唯一 ...

  4. LightOJ1336 Sigma Function

    题意 求和运算是一种有趣的操作,它来源于古希腊字母σ,现在我们来求一个数字的所有因子之和.例如σ(24)=1+2+3+4+6+8+12+24=60.对于小的数字求和是非常的简单,但是对于大数字求和就比 ...

  5. D - Sigma Function 1~n内有多少个约数和为偶数

    /** 题目:D - Sigma Function 链接:https://vjudge.net/contest/154246#problem/D 题意:求1~n内约数和为偶数的数的个数. 思路:一个数 ...

  6. 【LightOJ1336】Sigma Function(数论)

    [LightOJ1336]Sigma Function(数论) 题面 Vjudge 求和运算是一种有趣的操作,它来源于古希腊字母σ,现在我们来求一个数字的所有因子之和.例如σ(24)=1+2+3+4+ ...

  7. Sigma Function LightOJ - 1336 (约数和为奇数)

    题意: 求1-n中约数和为偶数的数的个数 记住一个定理:...平方数 及其 平方数的2倍 的约数和为奇数  then....减啦 证明: ....我jiao着人家写的很详细,so 看看人家写的吧! 转 ...

  8. Sigma Function (平方数与平方数*2的约数和是奇数)

    Sigma Function https://vjudge.net/contest/288520#problem/D Sigma function is an interesting function ...

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

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

随机推荐

  1. myeclipse的项目导入到eclipse下,com.sun.org.apache.commons.beanutils.BeanUtils不能导入

    com.sun.org.apache.commons.beanutils.BeanUtils这个包不能引入了怎么办自己下了个org.apache.commons的jar包了之后,改成import or ...

  2. 微信电脑版即将到来了 安装QQ浏览器微信版体验吧

    之前说过在手机上微信打字慢,tx最终还是想开了,最近TX邀请测试微信电脑版,想要尝鲜的朋友可以去exp.qq.com申请QQ浏览器微信版体验,不过体验将要结束了,相信正式版很快就要出来了.[微信网页版 ...

  3. hihoCoder挑战赛11.题目4 : 高等理论计算机科学(LCA)

    clj在某场hihoCoder比赛中的一道题,表示clj的数学题实在6,这道图论貌似还算可以... 题目链接:http://hihocoder.com/problemset/problem/1167 ...

  4. 将json返回的日期格式转换

    <script>         function ChangeDateFormat(cellval) {             var date = new Date(parseInt ...

  5. lua练手基础

    lua的库文件地址: http://luaforge.net/projects/lua官网 http://lua.org --[[ print string. multiple line commen ...

  6. ios中二维码的使用之一: 二维码的生成

    iOS在7之后,具备了原生的二维码生成API; 生成二维码的准备:  #import <CoreImage/CoreImage.h> 导入框架: 开始生成: //1- 创建过滤器 CIFi ...

  7. 160809209_李梦鑫_C语言程序设计实验3 循环结构程序设计

    <C语言程序设计>实验报告 学 号 160809209 姓 名 李梦鑫 专业.班 计科16-2班 学    期 2016-2017 第1学期 指导教师 黄俊莲 吉吉老师 实验地点 C05 ...

  8. 跟着百度学PHP[4]-OOP面对对象编程-3-实例化一个对象

    当定义好类后,我们使用new关键字来实例化一个对象! 格式: $object = new 类名; <?php class Person{ private $name; "; priva ...

  9. PyCharm 5 破解注册方法

    方法: 调整时间到2038年. 申请30天试用 退出pycharm 时间调整回来即可. 或者: 注册时选择 License server ,填 http://idea.lanyus.com ,然后点击 ...

  10. dp水题 序列问题 (9道)

    9道题.A了8道,A题看题解也没弄懂怎么维护m段子序列的,过一段时间再回来看看     dp试水 47:56:23 125:00:00   Overview Problem Status Rank ( ...