Problem 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

题意:t 组数据,每组给出 1 个数 n,求 1~n 中,所有数的约数和是偶数的数的个数

思路:

通过给的 

可以发现,式子中的每一项都是一个等比数列  的和

那么,

因此,对于式子 ,只要其中的一项为偶数,那么  就一定为偶数,故而只要找到一项为偶数就可以

观察式子可以发现:当  为偶数时,那么  一定为偶数,而 ,那么由于 1+偶+偶+...+偶=奇,因此  一定是一个奇数,那么,只有当  为奇数时, 才可能为偶数

再看 

  • 当  为偶数时,此时有偶数个奇数项,则:1+奇+奇+...+奇=奇,此时  仍为一个奇数
  •  为奇数时,此时有奇数个奇数项,则:1+奇+奇+...+奇=偶,此时  才是一个偶数

因此,对 n 做素因子分解,只要存在一个  均为奇数,那么  就一定为偶数

然而这样做会 TLE,因此还要进一步的推导:

我们可以考虑使用 总数-不满足的数=满足的数 来求解,也即求出所有  不均为奇数的数

当素因子分解后,有四种形式:奇^奇、偶^偶、奇^偶、偶^奇,根据前面的分析,只有当  均为奇数时, 才为偶数

那么,如果当素因子分解后,全是 偶^偶、奇^偶、偶^奇 的形式,因子和就一定为奇数

由于 2 是唯一的偶素数,我们将这个特殊的数拿出来分开考虑,根据唯一分解定理

那么:

  • 当  为偶数时,有 偶^偶、奇^偶 两种情况,其能拆成某个数的平方,即:偶^偶=( 偶^(偶/2) )^2、奇^偶=( 奇^(偶/2) )^2,那么 偶^奇、奇^偶 则两种情况就被 n 以内的平方数 给包含了,即有  种情况
  • 当  为奇数时,有 偶^奇 一种情况,由于其一定能拆成 2*x^2 的形式,那么 偶^奇 的情况就被 n 以内的 2*平方数 给包含了,即有  种情况

故最后结果为:

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define PI acos(-1.0)
#define E 1e-9
#define INF 0x3f3f3f3f
#define LL long long
const int MOD=10007;
const int N=1000000+5;
const int dx[]= {-1,1,0,0};
const int dy[]= {0,0,-1,1};
using namespace std;
int main(){int t;scanf("%d",&t);int Case=1;while(t--){LL n;scanf("%lld",&n);LL temp1=(LL)sqrt(n);LL temp2=(LL)sqrt(n/2);printf("Case %d: %lld\n",Case++,n-temp1-temp2);}return 0;
}

Sigma Function(LightOJ-1336)相关推荐

  1. Help Hanzo(LightOJ - 1197)(欧拉筛 + 思维)

    LightOJ - 1197 Help Hanzo 来源:LightOJ - 1197 Help Hanzo 题意: 判断a ~ b区间内,有多少个素数,a,b范围[1, 2 ^ 31 - 1],b ...

  2. Origin软件中Correlation function(关联/相关函数)原理剖析

    目录 Correlation计算原理 Correlation算法 Correlation计算原理 关联(Correlation)是两个随机变量或信号之间的数学关系.在统计中,可以将相关性视为归一化的协 ...

  3. 【 MATLAB 】Rational Transfer Function(有理传递函数)

    这算是学习MATLAB中的函数filter需要提前知道的理论基础知识,如果学过数字信号处理一定不会陌生,甚至能信手拈来. 其实英文版已经能看了,如果觉得不方便,那么最后也给出中文版. 英文版: Rat ...

  4. HDU-6750:Function(容斥)

    Function Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...

  5. 【ZJOI2009】【BZOJ1432】Function(找规律)

    problem n条直线,没有任意三条及以上直线相交于同一点. 求从下往上第k层(具体见原题)最少能被划分成多少条线段. solution n条边两两相交可以截出n^2段线段(自己画画就出来了QAQ) ...

  6. HDU 6750 Function(莫比乌斯反演)(2020百度之星初赛1)

    Function 推式子 S(n)=∑i=1n∑d∣id[gcd(d,id)==1]=∑d=1nd∑d∣i[gcd(d,id)==1]=∑d=1nd∑i=1nd[gcd(d,i)==1]=∑d=1nd ...

  7. 2021牛客暑期多校训练营1 H-Hash Function(数学+FFT)

    H-Hash Function Shining_xzl大佬题解 本题答案符合题意的充分必要条件是:不能是任意两个数的差以及他们的因数,因此只需用用FFT求出这些数的差,记为差的集合. 从小到大考虑一个 ...

  8. 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 F. Trig Function(切比雪夫定理)

    题目:https://nanti.jisuanke.com/t/17119 题意:找f(x)的x^m项的系数 思路:首先要找到公式啊 (还是别人发的,自己没找到 这样的话就可以直接按照公式找系数 代码 ...

  9. vba中function(自定义函数)

    案例: 参数不定的自定义函数: 参数值默认和参数缺省: ps:如果上面看懂了,下面就不用看了,不然看的头疼! ByVal是值传递,ByRef是地址传递 回顾11章中的内容: ByVal是值传递,ByR ...

最新文章

  1. DisplayMetrics
  2. 生成建表脚本up_CreateTable
  3. linux deepin ubuntu apt安装openjdk-8-jdk
  4. boost::gil::compute_harris_responses用法的测试程序
  5. 互联网架构阶段 数据库读写分离 Amoeba
  6. CF536C-Tavas and Pashmaks【凸壳】
  7. 静态代理、动态代理、AOP
  8. computational science education project
  9. 外贸人不知道的Facebook广告营销技巧和营销工具
  10. Webpack 中 resolve 路径解析
  11. python杨辉三角函数_Python算法之六:杨辉三角
  12. MySQL5.7 服务 crash 后无法启动
  13. PDF格式分析(六十五) Text 文字——字体数据结构
  14. windows 设置定时锁屏
  15. MAC地址_IP地址
  16. 我来告诉你2019新版微信转发语音消息的方法!就是这么简单
  17. SMS模型格网转换为MIKE21的格网源代码
  18. Consider revisiting the entries above or defining a bean of type in your configuration.
  19. 《统计学习方法》(李航)的学习体会(一)
  20. 零延迟!海康大华宇视网络监控摄像头RTSP浏览器网页无插件播放终极解决方案

热门文章

  1. Delphi 2009 之 TCategoryPanelGroup[5]: HeaderStyle
  2. 详解SaaS产品的5类核心指标
  3. TensorFlow和Keras入门必读教程
  4. 芯片内部长啥样?牛人用1500张照片,一层层放给你
  5. python模块导入视频教程_63-知识点回顾-函数和导入模块
  6. 这个开源组织里的项目都是精品
  7. 再见了Spring!这个架构有点厉害,甚至干掉了Dubbo!
  8. 绝了!这款工具让 Spring Boot 不在需要 Controller、Service、DAO、Mapper 了
  9. 胡润富豪榜2020出炉,雷军身价是任正非的十倍?
  10. 已火 2 年,Service Mesh究竟给微服务带来了什么?