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. docker容器备份、恢复和迁移volume方案

    volume作为数据的载体,在很多情况下需要对其中的数据进行备份.迁移或是恢复.下面一docker容器的volume为例,说一下备份的技巧. 我们先建立一个容器vol_simple,该容器在/date ...

  2. java String 内存模型

    关于java的内存模型,参照以下的一篇文章: https://isudox.com/2016/06/22/memory-model-of-string-in-java-language/

  3. git fetch 、git pull 与 git pull --rebase

    1. git fetch 与 git pull 都是从远程拉取代码到本地,git fetch只是拉取到本地,git pull不仅拉取到本地还merge到本地分支中.所以git pull是git fet ...

  4. java极光推送记录

      1. 添加poom依赖: <dependency> <groupId>cn.jpush.api</groupId> <artifactId>jigu ...

  5. 【sping揭秘】9、容器内部事件发布(二)

    写在前面---------------------------------- 命运多舛,痴迷淡然 不知下一步该往哪里走,现在应该是我的迷茫期... 加油,快点走出去!!! 聪明的网友们,你们有没有迷茫 ...

  6. 使用webpack和react搭建项目

    看了N多博客,日志,一边迷茫一边摸索.本文记录流程.我怕自己忘了...并且修复了博客园首页推荐那个日志中遇到的bug 1.webstorm新建一个空白项目,比如webpack_demo 2.因为要用r ...

  7. linux 下NFS远程目录挂载

    NFS 是Network File System的缩写,中文意思是网络文件系统.它的主要功能是通过网络(一般是局域网)让不同的主机系统之间可以共享文件或目录.NFS客户端(一般为应用服务器,例如web ...

  8. java中result和resultSet

    ResultSet: 1,定义         public interface ResultSet 表示数据库结果集的数据表,通常通过执行查询数据库的语句生成. 2,获得         State ...

  9. 剑指offer一之二维数组中的查找

    一.题目: 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. 二.解答方法: 方法 ...

  10. vue使用代理实现开发阶段跨域

    在config/index.js找到 proxyTable对象,添加键值对即可. "/api":{ target:"http://192.168.1.1", c ...