hdu 2608 0 or 1(数论推理)
2015-08-31 19:58
295 查看
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2608
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2947 Accepted Submission(s): 795
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
Sample Output
Author
yifenfei
分析:这是我目前见过的最棒的数论题了。数论题就是这样,代码简洁而优雅。
0 or 1
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2947 Accepted Submission(s): 795
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 HintHint S(3) = T(1) + T(2) +T(3) = 1 + (1+2) + (1+3) = 8 S(3) % 2 = 0
Author
yifenfei
分析:这是我目前见过的最棒的数论题了。数论题就是这样,代码简洁而优雅。
/* 在所有的素因子中只有2是偶数,设number=2^p0*k1^p1*k2^p2*……*kn^pn, 那么T(n)=(1+2^1+2^2+……+2^p0)*(1+k1^1+……+k1^p1)*……*(1+kn^1+……+kn^pn) 因为(1+2^1+2^2+……+2^p0)%2=1,所以问题集中于(1+k1^1+……+k1^p1)*……*(1+kn^1+……+kn^pn) 如果pi是一个奇数那么就有一个式子的结果是偶数(偶数个奇数是偶数)。 然后(1+k1^1+……+k1^p1)*……*(1+kn^1+……+kn^pn)%2=0.那么反过来想,所有的pi都是偶数的话 (1+k1^1+……+k1^p1)*……*(1+kn^1+……+kn^pn)%2=1(奇数个奇数是奇数,奇数乘以奇数还是奇数), 满足条件“所有的pi都是偶数”的数字(1+k1^1+……+k1^p1)*……*(1+kn^1+……+kn^pn)必然是另一个数字的平方。 所以number必然是里一个数字的平方(p0是偶数)或者一个数字平方的2倍(p0是奇数) */ #include <iostream> #include <cstdio> #include <cmath> using namespace std; int main() { int t,n; cin>>t; while(t--){ scanf("%d",&n); int res=(int)sqrt(n*1.0)+(int)sqrt(n*1.0/2); printf("%d\n",res%2); } return 0; }
相关文章推荐
- 最小的K个数
- 条件DP UVA 672 Gangsters
- Message在Dialog的用法
- Swift UILabel 文字大小随着宽度调整
- C语言的整型溢出问题(转)
- 5个常见的RuntimeException
- OC01_类和对象
- HDU 1060.Leftmost Digit【重点在分析】【格式【晕】】【8月31】【记录】
- 重新认识链表(单向链表并遍历)
- 简单的仿QQ聊天(自娱自乐聊天室)
- python中遍历dict的value
- [Leetcode] Basic Calculator
- java学习个人笔记---java内存管理之Java对象的引用方式
- C语言--变量的存储
- FI中替代和校验的几个相关函数
- HDU3435A new Graph Game(KM最小费用圈覆盖)
- 使用VMware WorkStation安装fedora出现section does not end with %%end错误的解决
- 石子归并问题(nyoj737)
- 社説 20150831 地熱発電 豊富な資源を有効活用しよう
- 关于JSONArray明明添加add JSONObject却为空