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. 【转】C# 之泛型详解

    原文地址:https://www.cnblogs.com/yueyue184/p/5032156.html 什么是泛型 我们在编写程序时,经常遇到两个模块的功能非常相似,只是一个是处理int数据,另一 ...

  2. 【BZOJ2002】 [Hnoi2010]Bounce 弹飞绵羊

    BZOJ2002 [Hnoi2010]Bounce 弹飞绵羊 Solution 很早以前写的一道分块题,最近在搞LCT,又做了一遍. 1.LCT做法 看到这种动态修改,想下LCT怎么维护. 修改操作就 ...

  3. 通过javascript 直接播放amr格式的语言

    前段时间做了个功能(有2.3个月了,突然想起来了,就记录一下),语言播放.一开始觉得很简单~~~ 计划应用的是H5的audio标签,但因为这个标签不支持amr格式的语言,但是手机端传到后台的录音却都是 ...

  4. skynet inject address file.lua

    inject d test/inject_fuck.lua -- d 是服务的 handle 拿 simpledb.lua 举例,修改如下 local skynet = require "s ...

  5. 自用 docker-compose

    version: '3.1' services: mysql: image: mysql: command: --default-authentication-plugin=mysql_native_ ...

  6. [Spring]IOC控制反转和DI依赖注入

    从之前算起到现在接触Spring也已经有几天了,进度也不是很快,就只弄懂了控制反转和依赖注入那么一点东西.然后敲了两个demo 主要是因为之前没有学过,然后网上资源很多但是都不是面向我们初学者的,大多 ...

  7. POJ 2521

    #include <iostream> #include <stdio.h> using namespace std; int main() { //freopen(" ...

  8. python面试(3)

    一.语言 推荐一本看过最好的python书籍? 拉开话题好扯淡 谈谈python的装饰器,迭代器,yield? 标准库线程安全的队列是哪一个?不安全的是哪一个?logging是线程安全的吗? pyth ...

  9. IDEA快捷键--与Eclipse快捷键的对比--IDEA快捷键设置成Eclipse默认快捷键

    部分内容转载于:http://blog.csdn.net/dc_726/article/details/9531281 IntelliJ Idea 常用快捷键列表 Ctrl+Alt+t 选择代码块 t ...

  10. 微信小程序(wx:for)遍历对象

    最近在折腾微信小程序,遇到这么一个情况:后端返回一个key-value的对象数据,需要遍历对象的key-value,然后渲染到视图中.就像下面这样: { '2018-1-9':{ address: ' ...