Uva 11395 Sigma Function (因子和)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=109329#problem/C 题目在文末
题意:1~n (n:1~1012)中,因子和为偶数的有几个。
题解:
因子和 Sum=(p1^0+p1^1….p1^e1)*(p2^0+p2^1…p2^e2)……(pn^0+…pn^en);
=
(p1^0+p1^1….p1^e1),(p2^0+p2^1…p2^e2),……(pn^0+…pn^en)中只要有一个是偶数,因子和sum就为偶数。所以只要找到一个是偶数就可以了。
若pi为偶数,则pi^x(x>0)为偶数,而pi^0=1(1+偶+偶….为奇数)。So,(pi^0+pi^1+…pi^ei)为奇数。所以pi只能是奇数,才能使(pi^0+pi^1+…pi^ei)为偶数。
再看pi^x (若x为奇数,pi^x为奇数(奇*奇*…为奇)),So,(pi^0+pi^1+…pi^ei)为偶数(1+奇+奇…)
所以,对m素因子分解,只要存在一个pi,ei都为奇数的pi^ei,就能使sum为偶数。
然而这么做必定TLE(-。-;)
再想想,1~n中 有多少个数的素因子分解中存在pi^ei(奇^奇)。
3^(2k-1) * (1,2,3,4..n/3) (k>1&&3^(2k-1)<=n)
5^(2k-1) * (1,2,3,4…n/5)
….
prime[i]^(2k-1) * (1,2,3,…n/prime[i]) 能包含所有的解,然而还有好多重复的解。看着有点像容斥定理,但多了个条件。(prime[i]^1,prime[i]^3…容斥有问题)。想了好久,感觉这题好难,不会了。。
不会咋办,换个思路呗!
不过之前还是忍不住暴力了一下 果断TLE
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int N=1e6+; bool vis[N];
int prime[N],cnt;
void is_prime()
{
cnt=;
memset(vis,,sizeof(vis));
for(int i=;i<N;i++)
{
if(!vis[i])
{
prime[cnt++]=i;
for(int j=i+i;j<N;j+=i)
vis[j]=;
}
}
} bool is_even(long long n)
{
for(int i=;i<cnt&&prime[i]*prime[i]<=n;i++)
{
int count=;
if(n%prime[i]==)
{
while(n%prime[i]==)
{
n/=prime[i];
count++;
}
if(prime[i]&)
{
if(count&)
return true;
}
}
}
if(n>&&(n&))
return true;
return false;
} int main()
{
int t;
cin>>t;
is_prime();
for(int kase=;kase<=t;kase++)
{
long long n;
cin>>n;
long long count=;
for(long long i=;i<=n;i++)
{
if(is_even(i))
cout<<i<<endl;
count++;
}
printf("Case %d: %d\n",kase,count);
}
}
反过来想,什么时候因子和是奇数呢?
由前面的分析(只要存在一个pi,ei都为奇数的pi^ei,就能使sum为偶数),素因子分解后,全为奇^偶,偶^偶,偶^奇,因子和就是奇数。
2是唯一一个偶素数。(特别的就得拿出来分开考虑。。)
((数^(偶/2)*(数^(偶/2))....)^2,这不是平方数吗!(数指的是奇数||偶数) (包含了数^偶)
所以这些数是 平方数 || 2*平方数 。(想不通的可以拿奇^偶,偶^偶,偶^奇组合,发现全被 平方数 || 2*平方数 包含了)
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long LL; int main()
{
int t;
scanf("%d",&t);
for(int kase=;kase<=t;kase++)
{
LL n;
scanf("%lld",&n);
LL num1=(LL)sqrt((double)n);
LL num2=(LL)sqrt((double)n/2.0);
printf("Case %d: %lld\n",kase,n-num1-num2);
}
return ;
}
一开始说好的题目 (-。-;)
Sigma Function
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
Uva 11395 Sigma Function (因子和)的更多相关文章
- Sigma Function 数学 因子求和
Sigma function is an interesting function in Number Theory. It is denoted by the Greek letter Sigma ...
- LightOJ1336 Sigma Function(约数和为偶数的个数)
Sigma Function Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit ...
- 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+ ...
- LightOJ1336 Sigma Function —— 质因子分解、约数和为偶数
题目链接:https://vjudge.net/problem/LightOJ-1336 1336 - Sigma Function PDF (English) Statistics Forum ...
- Sigma Function (LightOJ - 1336)【简单数论】【算术基本定理】【思维】
Sigma Function (LightOJ - 1336)[简单数论][算术基本定理][思维] 标签: 入门讲座题解 数论 题目描述 Sigma function is an interestin ...
- 1336 - Sigma Function
1336 - Sigma Function PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB S ...
- Sigma Function (平方数与平方数*2的约数和是奇数)
Sigma Function https://vjudge.net/contest/288520#problem/D Sigma function is an interesting function ...
- D - Sigma Function 1~n内有多少个约数和为偶数
/** 题目:D - Sigma Function 链接:https://vjudge.net/contest/154246#problem/D 题意:求1~n内约数和为偶数的数的个数. 思路:一个数 ...
随机推荐
- JavaScript学习08 Cookie对象
JavaScript学习08 Cookie对象 JavaScript Cookie Cookie对象: Cookie是一种以文件的形式保存在客户端硬盘的Cookies文件夹中的用户数据信息(Cooki ...
- Ida动态修改android程序的内存数据和寄存器数值,绕过so文件的判断语句
我们继续分析自毁程序密码这个app,我们发现该程序会用fopen ()打开/proc/[pid]/status这个文件,随后会用fgets()和strstr()来获取,于是我们在strstr()处下个 ...
- ios网络编程学习
//网络访问获取数据//定义一个UIWebView属性,用来展示数据 @property (strong, nonatomic) IBOutlet UIWebView *myWebView; //.. ...
- IOS开发——01_第一个OC程序
本文目录 一.新建Xcode项目 二.运行项目 注:建议先学习C语言, 如果你还没有编程经验,看不懂的地方可以在评论区提出,本文使用的为Xcode6.1版本,与之前版本会有所差异,但总体不变. 另:还 ...
- c语言模拟实现oc引用计数
#include<stdio.h> #include<stdlib.h> //在c中引入 引用计数机制 // 要解决的问题: 1,指向某块动态内存的指针有几个? // ...
- 【读书笔记】iOS-iCloud编程
一,苹果云服务-iCloud. 苹果公司斥资10亿美元在北卡罗来纳州简历数所中心-iDataCenter,该数据中心面积为50万平方英尺,也是美国最大规模的数据中心之一. 二,配置iCloud. 1, ...
- 【读书笔记】iOS网络-使用推送通知
一,本地通知 本地通知有64位的最大限制.虽然,你依然可以调度通知,不过到到达的通知数被限定为接近64个,并且按照fireDate的顺序排序,系统会忽略掉其余的通知.这意味着如果现在有64个调用的本地 ...
- [转 载] android 谷歌 新控件(约束控件 )ConstraintLayout 扁平化布局
序 在Google IO大会中不仅仅带来了Android Studio 2.2预览版,同时带给我们一个依赖约束的库. 简单来说,她是相对布局的升级版本,但是区别与相对布局更加强调约束.何为约束,即控件 ...
- 我的android学习经历7
android签名后报错的问题 Duplicate id @+id/imageView, already defined earlier in this layout,android生成报错 这个是项 ...
- 学习Coding-iOS开源项目日志(四)
Hello,大家好,好久没写博客了,今天再次来研究研究Coding源码,久违了. 前 言:作为初级程序员,想要提高自己的水平,其中一个有效的学习方法就是学习别人好的项目.本篇开始会陆续更新本人对git ...