LightOJ - 1336 - Sigma Function(质数分解)
链接:
https://vjudge.net/problem/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 σ.
思路:
考虑质数的约数和可以看作\((1+p_1^1+p_1^2+...+p_1^{k1})*(1+p_2^1+p_2^2+...+p_2^{k2})...\)
考虑和为奇数情况。
存在素因子2时,(1+2^n)为奇数,则和为奇数。
其他素因子为奇数,奇数乘奇数为奇数,1+偶数为奇数,偶数乘奇数为偶数,则只有素因子的指数为偶数时满足和为奇数。
由此得到其他数都为平方数。或者时平方数*2
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9;
const int MAXN = 1e6+10;
const int MOD = 1e9+7;
LL n;
int main()
{
int t, cnt = 0;
scanf("%d", &t);
while(t--)
{
printf("Case %d:", ++cnt);
scanf("%lld", &n);
LL tmp = n;
tmp -= (LL)sqrt(n);
tmp -= (LL)sqrt(n/2);
printf(" %lld\n", tmp);
}
return 0;
}
LightOJ - 1336 - Sigma Function(质数分解)的更多相关文章
- LightOJ 1336 Sigma Function(数论 整数拆分推论)
--->题意:给一个函数的定义,F(n)代表n的所有约数之和,并且给出了整数拆分公式以及F(n)的计算方法,对于一个给出的N让我们求1 - N之间有多少个数满足F(x)为偶数的情况,输出这个数. ...
- LightOJ 1336 - Sigma Function
原题链接 基础数论中很经典的一道题 题意 给出了σ(n)的计算公式,让你找出整数1-n中有多少对应σ(n)的值是偶数. 思路 观察σ(n)的公式发现,每一个乘项都是 (piei+1 - 1) / (p ...
- 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+ ...
- LightOJ - 1336 Sigma Function(约数和+整数拆分)
题干中给出函数公式: 其中pi为n的每个素因数,ei为其个数.设该函数为F(x),其意义为x的约数之和.问在1-n中有多少x,令F(x)为偶数. 分析:设f(p)为(p^(e+1)-1)/(p-1). ...
- LightOJ 13361336 - Sigma Function (找规律 + 唯一分解定理)
http://lightoj.com/volume_showproblem.php?problem=1336 Sigma Function Time Limit:2000MS Memory L ...
- 1336 - Sigma Function
1336 - Sigma Function PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB S ...
- 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 ...
- LightOJ1336 Sigma Function —— 质因子分解、约数和为偶数
题目链接:https://vjudge.net/problem/LightOJ-1336 1336 - Sigma Function PDF (English) Statistics Forum ...
- 1336 - Sigma Functio
1336 - Sigma Function Sigma function is an interesting function in Number Theory. It is denoted by t ...
随机推荐
- 3. 键值对RDD
键值对RDD是Spark中许多操作所需要的常见数据类型.除了在基础RDD类中定义的操作之外,Spark为包含键值对类型的RDD提供了一些专有的操作在PairRDDFunctions专门进行了定义.这些 ...
- .Net Jpush极光推送
1.首先登陆极光官网注册账号 https://www.jiguang.cn/push 2.注册成功后,在应用管理中创建应用
- Navicat 连接mysql 报错: Authentication plugin caching_ sha2_password cannot be loaded
出现这个错误的时候, 网上的资料都是修改mysql的登录信息的, ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password ...
- 可分离滤波器设计高斯滤波 CUDA程序优化, 实验记录
环境:RTX2060 ,1920X1080p ,循环10次, kernal_size=8 一 .测试前128个线程拷贝到dst数据的性能 ,只测试行卷积, block=(128+2r)X1 1. 使 ...
- 深入理解JVM(五) -- 垃圾回收算法
上篇文章我们了解到哪些内存区域和哪些对象可以被回收,这篇文章我们就来了解一下具体的垃圾回收算法的思路,不讨论具体的实现. 一 最基础算法 标记-清除(Mark-Swap) 为什么说他是最基础的算法,因 ...
- 微信小程序 image组件坑
远程图片 在真机上测试时 image组件只能显示http请求的图片, 对https 与 //xxx.xxx.xx 之类的不能显示. 可显示 'http://img.alicdn.com/i2/8323 ...
- vue中v-if和v-for指令最好不要同时使用
建议不要在与v-for相同的元素上使用v-if.因为v-for指令的优先级高于v-if当它们处于同一节点.v-for 的优先级比 v-if 更高,这意味着 v-if 将分别重复运行于每个 v-for ...
- Python 实现自动导入缺失的库
原文:由浅入深:Python 中如何实现自动导入缺失的库? 作者:豌豆花下猫 在写 Python 项目的时候,我们可能经常会遇到导入模块失败的错误:ImportError: No module nam ...
- 中兴软开C++面经(一站式西安)- 2019秋招
大概是9.6发短信邀请面试,但是6号有三个面试+一个在线笔试,就打算先去平安产险,看中途能不能再面个云从,中兴后面再面.然而,平安等了差不多4个小时才面完,期间云从面试官打来电话,只能说抱歉.中兴本来 ...
- WebService接口学习【1】
工具: 1.Eclipse(or)IDEA编辑器 2.SoapUI测试工具 1.wsdl文件标签体的约束: 一:namespace:相当于文件的id 二:targetNamespace属性:用来指定s ...