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. 5. ASP.NET MVC 中的Areas【区域】是什么

    [PS返回上一篇:-->4.ASP.NET MVC 5.0 视图之模型绑定] 从ASP.NET MVC 2.0开始,微软就提供了一个新特性:Areas[区域].Areas仅仅是用来将大型程序拆分 ...

  2. [leetcode.com]算法题目 - Pascal's Triangle

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  3. solr 下载 有dist目录的(6需要8)

    http://archive.apache.org/dist/lucene/solr/ solr6 需要java8

  4. FunDA(17)- 示范:异常处理与事后处理 - Exceptions handling and Finalizers

    作为一个能安全运行的工具库,为了保证占用资源的安全性,对异常处理(exception handling)和事后处理(final clean-up)的支持是不可或缺的.FunDA的数据流FDAPipeL ...

  5. activemq在一台服务器上启动多个Broker

    步骤如下: 1.把整个conf文件夹复制一份,比如叫conf2 2.修改里面的activemq.xml文件 ①brokerName不能和原来的重复 ②数据存放的文件名称不能重复,比如<kahaD ...

  6. python线程死锁与递归锁

    死锁现象 所谓死锁: 是指两个或两个以上的进程或线程在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用,它们都将无法推进下去. 此时称系统处于死锁状态或系统产生了死锁,这些永远在互相等待 ...

  7. 解决ubuntu安装系统默认没有创建root用户

    安装ubuntu操作系统的时候,默认没有设置root账户的步骤!!! 这样在操作系统安装完成之后,就没有root用户, 一般,当前的普通用户,如果需要执行一些命令的时候,只要在命令前边加上sudo就行 ...

  8. Docker中使用createdump调试coreclr

    应用上线后可能出现一些问题,通过源码排查,日志分析都不能确定具体原因的情况下,可以使用dump转存文件分析,netcore对于linux系统dump提供了createdump工具,配合lldb sos ...

  9. Win7上Spark WordCount运行过程及异常

    WordCount.Scala代码如下: package com.husor.Spark /** * Created by huxiu on 2014/11/26. */ import org.apa ...

  10. Log4j 相关

    Log4j(Log for Java) Log4j是Apache提供的一种专门用于Java程序记录日志的工具,是目前主流的开发日志技术. 日志的作用: 1.记录系统运行过程中的重要运行信息 a) 付费 ...