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内约数和为偶数的数的个数. 思路:一个数 ...
随机推荐
- mousewheel
判断鼠标往上还是往下滚动 html代码: <div class="div"> </div> css代码: .div{ position:absolute; ...
- C#如何在钉钉开发平台中创建部门
钉钉是阿里巴巴专为中小企业和团队打造的沟通.协同的多端平台,钉钉开放平台旨在为企业提供更为丰富的办公协同解决方案.通过钉钉开放平台,企业或第三方合作伙伴可以帮助企业快速.低成本的实现高质量的移动微应用 ...
- HTML <b>、 <strong> 、<big>、<small>、<em>、<i>、<sub>和<sup> 标签
HTML <b> 标签 所有浏览器都支持 <b> 标签. 定义和用法 <b> 标签规定粗体文本. 注释:根据 HTML5 规范,在没有其他合适标签更合适时,才应该把 ...
- Android 手机卫士--安装过程中点击回退按钮
本文地址:http://www.cnblogs.com/wuyudong/p/5903707.html,转载请注明源地址. 在手机卫士之前的版本升级的对话框中: 有的用户暂时不想更新,没有点击“稍后再 ...
- iOS 全局断点崩溃
设置全局断点出现奔溃,可以点击继续运行不影响程序,不是程序的问题,webview和自定义xib View使用的时候
- 【代码笔记】iOS-把<br!>换成\n
代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // ...
- runtime之玩转成员变量
前言: 不铺垫那么多,单刀直入吧:runtime是一个C和汇编写的动态库,就像是一个小小的系统,将OC和C紧密关联在一次,这个系统主要做两件事情. 1,封装C语言的结构体和函数,让开发者在运行时创建, ...
- wifi强度数据采集器(android)
来源:毕业设计 关键词:wifi数据的采集 SQLite数据库的使用 需求 采集实验室内各坐标处各wifi信号的强度 UI 因为是辅助工具,所以UI写的很简单,如下图 Wifi相关操作 //获取Wif ...
- redis数据类型
Redis 数据类型 Redis支持五种数据类型:string(字符串),hash(哈希),list(列表),set(集合)及zset(sorted set:有序集合). String(字符串) st ...
- DB2常用sql命令
DB2 清除数据库序列缓存 alter sequence wfr.wfr_bill_histories_s nocache; 创建清空所有表数据脚本select 'alter table '||RT ...