0 or 1(hdu2608)数学题
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
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).
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.
integer S(n) %2. So you may see the answer is always 0 or 1 .
Hint S(3) = T(1) + T(2) +T(3) = 1 + (1+2) + (1+3) = 8 S(3) % 2 = 0
【分析】
当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)数学题的更多相关文章
- java第二周的作业
package java第二周学习; import javax.swing.JOptionPane; public class 数学题 { private int a; private int b; ...
- NYOJ 618 追击
追击 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 因为洛丹伦南部的兽人暴动,不得不使人类联盟採取最后的手段进行镇压.国王泰瑞纳斯派出了两位最棒的圣骑士以遏制兽人的 ...
- 2015苏州大学ACM-ICPC集训队选拔赛(2) 1001 1003 1010
草爷要的榜 Problem Description 苏州大学代表队又勤奋地开始了训练.今天开了一场时长5小时的组队训练赛,苏州大学的n(1<=n<=100)支校队奋力拼(hua)搏(shu ...
- 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 ...
- 【T^T】【周赛】第一周周赛——欢迎16级的新同学
借光光,YZC的福气(今天拿到Rank1),本来还可以更好的,前面吃M去了,ABC都很晚切,而且异常兴奋,结果WA了好多发,但还是由于水题看题不清,分析不清导致的 A Home W的数学 Descri ...
- 002-python函数、高级特性
1.函数 1.1 定义函数 在Python中,定义一个函数要使用def语句,依次写出函数名.括号.括号中的参数和冒号:,然后,在缩进块中编写函数体,函数的返回值用return语句返回 自定义一个求绝对 ...
- HDU-1204-糖果大战
题目描述 生日\(Party\)结束的那天晚上,剩下了一些糖果,\(Gandon\)想把所有的都统统拿走,\(Speakless\)于是说:"可以是可以,不过我们来玩\(24\)点,你不是已 ...
- Codeforces #536 A..D 题解
foreword ummm... 开始前几个小时被朋友拉来打了这一场,总体海星,题目体验极佳,很符合口味,稍微有点点简单了不知道是不是因为是 New Year Round,很快就打到了 D,但是题目阅 ...
- 一文上手Python3
案例参考:廖雪峰--Python教程 基础知识 基本数据类型 用type()来判断数据类型: In [1]: type(1) Out[1]: int In [2]: type(1.0) O ...
- X000011
P1890 gcd区间 \(\gcd\) 是满足结合律的,所以考虑用 ST 表解决 时间复杂度 \(O((n\log n+m)\log a_i)\) 考虑到 \(n\) 很小,你也可以直接算出所有的区 ...
随机推荐
- 前台获取枚举的key值
如: Enum ShowPosition { 首页 = 0,一级分类页 = 1,二级分类页 = 2 } 想获得汉字对应的数字,可用GetHashCode() html展示如下:循环枚举 @foreac ...
- hash的安全性
在区块链中,我们面临着两个问题: 隐私问题 快速对账问题 由于区块链中,每个人都存在着一个账本,当一个人有收入的时候,将会进行广播到所有人的账本,例如张三收入xxx钱,这样子所有的账本才能同步更新.但 ...
- Python测试 ——开发工具库
Web UI测试自动化 splinter - web UI测试工具,基于selnium封装. selenium - web UI自动化测试. mechanize- Python中有状态的程序化Web浏 ...
- C语言判断进程是否存在
#include <windows.h> #include <tlhelp32.h> //进程快照函数头文件 #include <stdio.h> bool get ...
- 如何执行超过一百兆(100MB)的sql脚本?
最近遇到一个问题,在sqlserver的查询分析器里面执行一个超过100MB的数据库脚本,发现老是报“引发类型为“System.OutOfMemoryException”的异常”,上网查了一下,主要是 ...
- activemq在一台服务器上启动多个Broker
步骤如下: 1.把整个conf文件夹复制一份,比如叫conf2 2.修改里面的activemq.xml文件 ①brokerName不能和原来的重复 ②数据存放的文件名称不能重复,比如<kahaD ...
- SQL面试题之行转列
典型的课程表: mysql> select * from course; +----+------------+----------+------------+ | id | teacher_i ...
- 读取excel合并单元格内容
def get_excel_content(excel_path): contents = [] if self.log_path.endswith('xls'): workbook = xlrd.o ...
- 使用反射功能在Unity运行状态通过Inspector面板修改字段和调用方法
使用反射功能在Unity运行状态通过Inspector面板修改字段和调用方法 效果展示 一个很简单的组件脚本 运行状态在Inspector面板可以随便修改字段和调用方法 方法调用日志 设计由来 最近在 ...
- Docker三剑客之常用命令
一.docker-machine 命令 说明 docker-machine create 创建一个 Docker 主机(常用-d virtualbox) docker-machine ls 查看所有的 ...