0 or 1

Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2391 Accepted Submission(s):
594

Problem Description
Solving problem is a interesting thing. Yifenfei like
to slove different problem,because he think it is a way let him more
intelligent. But as we know,yifenfei is weak in math. When he come up against a
difficult math problem, he always try to get a hand. Now the problem is coming!
Let we
define T(n) as the sum of all numbers which are positive integers can
divied n. and S(n) = T(1) + T(2) + T(3)…..+T(n).
 
Input
The first line of the input contains an integer T which
means the number of test cases. Then T lines follow, each line consists of only
one positive integers n. You may assume the integer will not exceed 2^31.
 
Output
For each test case, you should output one lines of one
integer S(n) %2. So you may see the answer is always 0 or 1 .
 
Sample Input
3
1
2
3
 
Sample Output
1
0
0
 
Hint

Hint S(3) = T(1) + T(2) +T(3) = 1 + (1+2) + (1+3) = 8 S(3) % 2 = 0

 
 
初看这道题目挺简单的不是吗0 or 1,关键是找到解题的入口
现在来分析一下:

【分析】
当N=10;
1
1 2
1 3
1 2 4
1 5
1 2 3 6
1 7
1 2 4 8
1 3 9
1 2 5 10
注意到不要单行相加,按来加,有10个1,5个2,3个3,2个4和5,1个6,7,8,9,10,
看到这里,我立刻就醒过省来了;
10/1=10,10/10=1,s+=10;
10/2=5,10/5=2,s+=5*2;
10/3=3,10/3=3,s+=3*3;
10/4=2,10/2=5,s+=(4+5)*2;//按区间算;
10/6=1,10/1=10,s+=(6+7+8+9+10)*1;//按区间算;

 
#include<stdio.h>
int count(int x)
{ if(x==)
return ;
int i,j,w,m,s=x;
for(i=;i<=x;)
{
w=x/i;
m=x/w;
if(m==i)
{
i++;
s+=(w*m)%;
s%=;
}
else
{
int t=(i+m)*(m-i+)/;//连续区间,等差求和;(6+10)*(10-6+1)/2;
s+=(t*w)%;
s%=;
i=m+;//令i=x+1,退出;
}
}
return s;
}
int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
printf("%d\n",count(n));
}
return ;
}
看了网上的另一种算法,发现代码更简洁思路更清晰,但是时间比我代码久,
分析是这样的;

分析:假设数n=2^k*p1^s1*p2^s2*p3^s3*...*pi^si;//k,s1...si>=0,p1..pi为n的素因子
所以T[n]=(2^0+2^1+...+2^k)*(p1^0+p1^1+...+p1^s1)*...*(pi^0+pi^1+...+pi^si);
显然(2^0+2^1+...+2^k)%2=1,所以T[n]是0或1就取决于(p1^0+p1^1+...+p1^s1)*...*(pi^0+pi^1+...+pi^si)
而p1...pi都是奇数(除2之外的素数一定是奇数),所以(pi^0+pi^1+...+pi^si)只要有一个si为奇数(i=1...i)
则(pi^0+pi^1+...+pi^si)%2=0,则T[n]%2=0//若si为奇数,则pi^si+1为偶数,pi^1+pi^2+...+pi^(si-1)为偶数(偶数个奇数和为偶数)
所以要T[n]%2=1,则所有的si为偶数,则n=2^(k%2)*m^2;//m=2^(k/2)*p1^(s1/2)*p2^(s2/2)*...*pi^(si/2)
所以只要n为某个数的平方或者某个数的平方和则T[n]%2=1,只要统计n的个数即可

简而言之:数为1的是某数的平方或某数平方的2倍,之前结果之和取余

 #include <stdio.h>
#include<math.h>
int main()
{
int t,sum;
__int64 n,i,k;
scanf("%d",&t);
while(t--)
{
scanf("%I64d",&n);
sum=k=(int) sqrt(n);//前面有几个平方
for(i=;i<=k;i++)
{
if(i*i*<=n)
sum++;
}
sum=sum%;
printf("%d\n",sum);
}
return ;
}

or

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std; int main()
{
int t,n;
cin>>t;
while(t--)
{
cin>>n;
int sum=(int)sqrt(n*1.0)+(int)sqrt(n*1.0/);
cout<<sum%<<endl;
}
return ;
}
 
 
 
 
 

0 or 1(hdu2608)数学题的更多相关文章

  1. java第二周的作业

    package java第二周学习; import javax.swing.JOptionPane; public class 数学题 { private int a; private int b; ...

  2. NYOJ 618 追击

    追击 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 因为洛丹伦南部的兽人暴动,不得不使人类联盟採取最后的手段进行镇压.国王泰瑞纳斯派出了两位最棒的圣骑士以遏制兽人的 ...

  3. 2015苏州大学ACM-ICPC集训队选拔赛(2) 1001 1003 1010

    草爷要的榜 Problem Description 苏州大学代表队又勤奋地开始了训练.今天开了一场时长5小时的组队训练赛,苏州大学的n(1<=n<=100)支校队奋力拼(hua)搏(shu ...

  4. Codeforces 371BB. Fox Dividing Cheese

    Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, corre ...

  5. 【T^T】【周赛】第一周周赛——欢迎16级的新同学

    借光光,YZC的福气(今天拿到Rank1),本来还可以更好的,前面吃M去了,ABC都很晚切,而且异常兴奋,结果WA了好多发,但还是由于水题看题不清,分析不清导致的 A Home W的数学 Descri ...

  6. 002-python函数、高级特性

    1.函数 1.1 定义函数 在Python中,定义一个函数要使用def语句,依次写出函数名.括号.括号中的参数和冒号:,然后,在缩进块中编写函数体,函数的返回值用return语句返回 自定义一个求绝对 ...

  7. HDU-1204-糖果大战

    题目描述 生日\(Party\)结束的那天晚上,剩下了一些糖果,\(Gandon\)想把所有的都统统拿走,\(Speakless\)于是说:"可以是可以,不过我们来玩\(24\)点,你不是已 ...

  8. Codeforces #536 A..D 题解

    foreword ummm... 开始前几个小时被朋友拉来打了这一场,总体海星,题目体验极佳,很符合口味,稍微有点点简单了不知道是不是因为是 New Year Round,很快就打到了 D,但是题目阅 ...

  9. 一文上手Python3

      案例参考:廖雪峰--Python教程   基础知识 基本数据类型   用type()来判断数据类型: In [1]: type(1) Out[1]: int In [2]: type(1.0) O ...

  10. X000011

    P1890 gcd区间 \(\gcd\) 是满足结合律的,所以考虑用 ST 表解决 时间复杂度 \(O((n\log n+m)\log a_i)\) 考虑到 \(n\) 很小,你也可以直接算出所有的区 ...

随机推荐

  1. “全栈2019”Java多线程第二十八章:公平锁与非公平锁详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...

  2. Elasticsearch重要文章之四:监控每个节点(ThreadPool部分)

    http://zhaoyanblog.com/archives/754.html ThreadPool部分 Elasticsearch 内部使用了线程池,通过这些线程池之间的合作完成工作,在需要时传递 ...

  3. 《Python自动化运维之路》 业务服务监控(二)

    文件内容差异对比方法 使用diffie模块实现文件内容差异对比.dmib作为 Python的标准库模块,无需安装,作用是对比文本之间的差异,且支持输出可读性比较强的HTML文档,与 Linux下的di ...

  4. com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

    出现上述bug的原因如下: 在默认设置下,Eureka服务注册中心也会将自己作为客户端来尝试注册它自己,所以我们需要禁用它的客户端注册行为. 禁止方式如下:在application.propertie ...

  5. [JavaScript] Nginx实现跨域设置

    假如跨域请求的接口为:http://xxx.cn/was5/web/search Nginx配置: 在conf/nginx.conf文件中 location / { root html; index ...

  6. git使用分支与tag

    查看分支:git branch 创建分支:git branch <name> 切换分支:git checkout <name> 创建+切换分支:git checkout -b ...

  7. Java入门-类HelloWorld是公共的,应在名为HelloWorld.java的文件中声明

    开始学习java了,搭好环境,notepad++中新建一个java文件,新建一个HelloWorld类, public class HelloWorld { public static void ma ...

  8. 【sping揭秘】3、Spring容器中bean默认是保持一个实例

    Spring容器中bean默认是保持一个实例 这里做一个测试,基础代码 package cn.cutter.start.provider; import org.springframework.con ...

  9. dubbo源码阅读之SPI

    dubbo SPI SPI,全程Service Provider interface, java中的一种借口扩展机制,将借口的实现类注明在配置文件中,程序在运行时通过扫描这些配置文件从而获取全部的实现 ...

  10. CentOS7.x编译安装nginx,实现HTTP2

    网站使用HTTP2有助于网站加速及更安全,要配置HTTP2必须满足两个条件:①openssl的版本必须在1.0.2e及以上.②nginx的版本必须在1.9.5以上 一.准备工作  配置HTTP2之前需 ...