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 (因子和)的更多相关文章

  1. Sigma Function 数学 因子求和

    Sigma function is an interesting function in Number Theory. It is denoted by the Greek letter Sigma ...

  2. LightOJ1336 Sigma Function(约数和为偶数的个数)

    Sigma Function Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit ...

  3. LightOJ 13361336 - Sigma Function (找规律 + 唯一分解定理)

    http://lightoj.com/volume_showproblem.php?problem=1336 Sigma Function Time Limit:2000MS     Memory L ...

  4. 【LightOJ1336】Sigma Function(数论)

    [LightOJ1336]Sigma Function(数论) 题面 Vjudge 求和运算是一种有趣的操作,它来源于古希腊字母σ,现在我们来求一个数字的所有因子之和.例如σ(24)=1+2+3+4+ ...

  5. LightOJ1336 Sigma Function —— 质因子分解、约数和为偶数

    题目链接:https://vjudge.net/problem/LightOJ-1336 1336 - Sigma Function    PDF (English) Statistics Forum ...

  6. Sigma Function (LightOJ - 1336)【简单数论】【算术基本定理】【思维】

    Sigma Function (LightOJ - 1336)[简单数论][算术基本定理][思维] 标签: 入门讲座题解 数论 题目描述 Sigma function is an interestin ...

  7. 1336 - Sigma Function

    1336 - Sigma Function   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB S ...

  8. Sigma Function (平方数与平方数*2的约数和是奇数)

    Sigma Function https://vjudge.net/contest/288520#problem/D Sigma function is an interesting function ...

  9. D - Sigma Function 1~n内有多少个约数和为偶数

    /** 题目:D - Sigma Function 链接:https://vjudge.net/contest/154246#problem/D 题意:求1~n内约数和为偶数的数的个数. 思路:一个数 ...

随机推荐

  1. Exchange 2013 、Lync 2013、SharePoint 2013 三

    前两篇介绍的是关于Exchange 与 Lync 之间的配制关系,这一篇介绍关于Lync.Exchange 与 SharePoint 之间建立信任关系. 首先要创建基于SSL的SharePoint A ...

  2. JavaScript 经典实例收集整理

    跨浏览器添加事件 //跨浏览器添加事件 function addEvent(obj,type,fn){ if(obj.addEventListener){ obj.addEventListener(t ...

  3. 学习笔记——关于HTML(含HTML5)的块级元素和行级(内联)元素总结

    1.首先我们要知道什么是块级元素和行级(内联)元素? 块级(block)元素的特点: ①总是在新行上开始: ②高度,行高以及外边距和内边距都可控制: ③宽度缺省是它的容器的100%,除非设定一个宽度: ...

  4. js调用soapWebService服务

    js调用soapWebService服务 什么是 SOAP? SOAP 指简易对象访问协议 SOAP 是一种通信协议 SOAP 用于应用程序之间的通信 SOAP 是一种用于发送消息的格式 SOAP 被 ...

  5. linux集群运维工具:pssh

    由于需要安装hadoop集群,有10台机器需要安装,一开始打算用SCP复制,后来觉得不可接受(实际现场可能数倍的机器集群,就是10台也不想干).后来在网上找了,发现了clustershell和pssh ...

  6. OC中的深拷贝与浅拷贝

    深拷贝(deep copy)与浅拷贝(shallow copy)的定义一直是有争论的. 一种理解是: 所谓的浅拷贝, 就是不完全的拷贝 NSString *s = @"123"; ...

  7. Java虚拟机JVM学习05 类加载器的父委托机制

    Java虚拟机JVM学习05 类加载器的父委托机制 类加载器 类加载器用来把类加载到Java虚拟机中. 类加载器的类型 有两种类型的类加载器: 1.JVM自带的加载器: 根类加载器(Bootstrap ...

  8. iOS常用手势识别器

    手势识别状态: typedef NS_ENUM(NSInteger, UIGestureRecognizerState) { // 没有触摸事件发生,所有手势识别的默认状态 UIGestureReco ...

  9. Android Studio Gradle Build Running 特别慢的问题探讨

    本文的本本win7 64bit 6G android studio2.1 在运行程序的时候Gradle Build Running 特别慢,一个helloworld都快2min了 1.开启gradle ...

  10. 终极指南:如何为iOS8应用制作预览视频

    最近一两个月里,苹果的世界里出现了很多新东西,比如屏幕更大的iPhone 6,可穿戴设备Apple Watch,iOS8,以及旨在帮助用户更好的发现应用的App Store改版等等. 说到App St ...