Sigma Function (LightOJ - 1336)【简单数论】【算术基本定理】【思维】
Sigma Function (LightOJ - 1336)【简单数论】【算术基本定理】【思维】
标签: 入门讲座题解 数论
题目描述
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
题意
约数和函数$$\sigma{(n)} = \sum_{d | n} d;.$$
给定\(n\),询问\([1, n]\)区间内有几个\(i\),使得\(\sigma{(i)}\)为偶数?
解析
根据算数基本定理,正整数\(n\),有唯一质因数分解形式,$$n = p_1^{\alpha_1}\cdot p_2^{\alpha_2} \cdot p_3^{\alpha_3} \cdot ,,\cdots ,, \cdot p_n^{\alpha_n}\quad(p_i ;is ;a ;prime).$$
那么,根据乘法计数原理,显然有\(\sigma{(n)} = (1 + p_1^1 + p_1^2 + \cdots p_1^{\alpha_1}) \cdot (1 + p_2^1 + p_2^2 + \cdots + p_2^{\alpha_2}) \cdot (1 + p_3^1 + p_3^2 + \cdots + p_3^{\alpha_3}) \cdot \,\, \cdots \,\, \cdot (1 + p_n^1 + p_n^2 + \cdots + p_n^{\alpha_n})\).
正难则反,我们不方便研究\(\sigma{(n)}\)为偶数的情况,我们可以研究\(\sigma{(n)}\)为奇数的个数,然后用总数减掉奇数个数,就得到偶数个数。
- 首先,我们要清楚
偶数 + 偶数 = 偶数
奇数 + 偶数 = 奇数
奇数 + 奇数 = 偶数偶数 * 偶数 = 偶数
奇数 * 偶数 = 偶数
奇数 * 奇数 = 奇数。
- 我们知道,只有让\(\sigma{(n)}\)的全部因数都为奇数才可以使\(\sigma{(n)}\)为奇数。
若\(2 \,| \,n\),则\((1 + p_1^1 + p_1^2 + \cdots p_1^{\alpha_1})\)这项一定是奇数。因为\(2\)的任何次幂都是偶数,且偶数 + 奇数 = 奇数。
对于除\(2\)以外的其他质数,它的任何次幂都一定是奇数。要想使因数项为奇数,则只能构造($1 + $ 偶数) 的这种形式.当有偶数个奇数相加时,它们的和是偶数。所以,\(\alpha_1,\alpha_2, \alpha_3, \dots,\alpha_n\)(不包括\(2\)的指数)都应该是偶数。
\(n\) 可以是一个完全平方数。当\(n\)是一个完全平方数时,\(\alpha_1,\alpha_2, \alpha_3, \dots,\alpha_n\)都是偶数。因为\(n\)可以找到两个完全相同的因子。
或者,\(n\)可以是$2 \times $ 完全平方数。因为把\(2\)当作底数的因数项永远是奇数,所以乘上\(2\)依然能保持所有乘数项都是奇数。(为什么没有$2^2, 2^3, 2^4, \dots \times $ 完全平方数?当\(2\)的指数为偶数时,用完全平方数就可以找到这个数。如果是奇数时,指数 = 1 + 偶数,又还原为$2 \times $ 完全平方数。)综上,\(ans = n - \sqrt{n} - \sqrt{n / 2}\)。
通过代码
/*
Problem
LightOJ - 1336
Status
Accepted
Time
151ms
Memory
2084kB
Length
411
Lang
C++
Submitted
2019-11-26 23:30:58
RemoteRunId
1641328
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int times, kase = 0;
scanf("%d", ×);
while(times --){
ll n, cnt = 0; //cnt也有可能会超过1e9,所以要声明为long long类型.
scanf("%lld", &n);
for(ll i = 1; i * i <= n; i ++){
cnt ++; //不超过n的完全平方数计数.
if(2 * i * i <= n)
cnt ++; //不超过n/2的完全平方数计数.
}
printf("Case %d: %lld\n", ++ kase, n - cnt);
}
return 0;
}
Sigma Function (LightOJ - 1336)【简单数论】【算术基本定理】【思维】的更多相关文章
- C - Sigma Function LightOJ - 1336 (数论)
一个让人脑洞大开的题. 题目大意比较简单,询问[1,n]有多少个数其因子和为偶数. 因子分解定理中求因子和的公式是 f(n)=(1+p1+p1^2+p1^3+...+p1^a1)(1+p2+p2^2+ ...
- Sigma Function LightOJ - 1336 (约数和为奇数)
题意: 求1-n中约数和为偶数的数的个数 记住一个定理:...平方数 及其 平方数的2倍 的约数和为奇数 then....减啦 证明: ....我jiao着人家写的很详细,so 看看人家写的吧! 转 ...
- Pairs Forming LCM (LightOJ - 1236)【简单数论】【质因数分解】【算术基本定理】(未完成)
Pairs Forming LCM (LightOJ - 1236)[简单数论][质因数分解][算术基本定理](未完成) 标签: 入门讲座题解 数论 题目描述 Find the result of t ...
- Aladdin and the Flying Carpet (LightOJ - 1341)【简单数论】【算术基本定理】【分解质因数】
Aladdin and the Flying Carpet (LightOJ - 1341)[简单数论][算术基本定理][分解质因数](未完成) 标签:入门讲座题解 数论 题目描述 It's said ...
- LightOJ - 1336 - Sigma Function(质数分解)
链接: https://vjudge.net/problem/LightOJ-1336 题意: Sigma function is an interesting function in Number ...
- LightOJ 13361336 - Sigma Function (找规律 + 唯一分解定理)
http://lightoj.com/volume_showproblem.php?problem=1336 Sigma Function Time Limit:2000MS Memory L ...
- 【LightOJ1336】Sigma Function(数论)
[LightOJ1336]Sigma Function(数论) 题面 Vjudge 求和运算是一种有趣的操作,它来源于古希腊字母σ,现在我们来求一个数字的所有因子之和.例如σ(24)=1+2+3+4+ ...
- 1336 - Sigma Function
1336 - Sigma Function PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB S ...
- Help Hanzo (LightOJ - 1197) 【简单数论】【筛区间质数】
Help Hanzo (LightOJ - 1197) [简单数论][筛区间质数] 标签: 入门讲座题解 数论 题目描述 Amakusa, the evil spiritual leader has ...
随机推荐
- How to: Map a Persistent Class to a Database View Which Has No Key Field如何:映射持久化类到无主键数据库视图
With XAF, you can build new applications from scratch or maintain existing databases. The How to: Ge ...
- 好的js书写习惯
1:单一判断 bad if (result) { console.log("秋叶"); } if (!result) { console.log("秋叶"); ...
- 【js】canvas——Atomic-particle-motion
原子粒动 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- [转]为何选择 Flink
本文转自:https://www.ituring.com.cn/book/tupubarticle/23229 第 1 章 为何选择 Flink 人们对某件事的正确理解往往来自基于有效论据的结论.要获 ...
- phpstudy漏洞检测
后门检测脚本 # !/usr/bin/env python # -*- coding:utf-8 -*- import gevent from gevent import monkey gevent. ...
- Android 无源码smail进行debug
待调试项目在AndroidManifest.xml中debugable=true 参照此处:https://blog.csdn.net/ausboyue/article/details/8018918 ...
- spring为类的静态属性实现注入
我们知道,正常情况下,spring的一个bean要依赖其他资源,如properties或其他bean,直接利用@Value或@Autowired就可以了.这两个注解就相当于spring applica ...
- mysql从5.6升级到5.7后出现 Expression #1 of ORDER BY clause is not in SELECT list,this is incompatible with DISTINCT
[问题]mysql从5.6升级到5.7后出现:插入数据和修改数据时出错Caused by: com.ibatis.common.jdbc.exception.NestedSQLException: - ...
- ceph安装笔记
配置源 ceph版本为luminous [root@ceph-node1 ~]# yum install -y https://dl.fedoraproject.org/pub/epel/epel-r ...
- C++ std::vector 基本用法2
#include <iostream> #include <vector> using namespace std; int main() { int ar[10] = { 1 ...