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内约数和为偶数的数的个数. 思路:一个数 ...
随机推荐
- 最近学习了Node,利用Express搭建了个人博客,总结下吧
node+express+jade+mongodb搭建了一套个人博客,我来总结下这几个家伙的使用感受吧! [node] 成熟插件库众多,真的是只有你想不到,没有它做不到的.而且对于有前端JS基础的童鞋 ...
- iOS 适配iOS9
1.网络接口不支持https协议,在iOS9下 在iOS9下,系统默认会拦截对http协议接口的访问,因此无法获取http协议接口的数据. 解决方案(以下方法2选1): (1)暂时退回到http协议 ...
- 一次失败的APP业务渗透测试
作者:whoamiecho 来源:ichunqiu 本文参加i春秋社区原创文章奖励计划,未经许可禁止转载! 一. 过程 1.1.事情起因:暴力破解 测试给了个普通用户账号,可以登录.APP一来就要登 ...
- 转:与Microsoft Visual Studio集成良好的第三方工具
我们都知道,Microsoft Visual Studio(简称VS)是微软开发的一个非常高效的集成开发环境,但即使已经发展到VS2012,仍然有许多不尽人意的地方.一般来讲,一个项目中需要有控件.代 ...
- Autodesk Cloud Accelerator Program 开始报名
如果你没有注意到这个消息,那你就会错过一个前往旧金山和硅谷工程师一起工作数周的机会. 摘要一下: 时间: 1月10前提交你的提案,3月飞往旧金山 地点: 旧金山. 包住宿哦~ 不过,既然要去美国,既然 ...
- Android之SeekBar定制
1.SeekBar样式定制 xml文件中: <SeekBar android:id="@+id/seekbar_voice" ...
- 代码创建storyboard
代码创建storyboard方式如下 // 加载storyboard UIStoryboard *storyboard = [UIStoryboard StoryboardWithName:@&quo ...
- css文本格式详解
一.css文本主体内容: 二.css文本详解: 1.文本缩进 语法: text-indent:<length>|<percentage> 默认值为0. 属性值详解: < ...
- 自动化部署与统一安装升级 - 类ansible工具 udeploy0.3版本发布 (更新时间2014-12-24)
下载地址: unifyDeploy0.1版本 unifyDeploy0.2版本 unifyDeploy0.3版本 (更新时间2014-07-25) 自动化部署与统一安装升级,适用于多资 ...
- C#复习④
C#复习④ 2016年6月16日 12:37 Main Classes and Structs 类和结构体 1.Contents of Classes 字段,常量,方法,构造函数,析构函数: 特性,事 ...