hdu 2608

来源:互联网 发布:淘宝开店审核在哪里看 编辑:程序博客网 时间:2024/05/17 20:11

0 or 1

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2264    Accepted Submission(s): 558


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
3123
 

Sample Output
100
Hint
Hint S(3) = T(1) + T(2) +T(3) = 1 + (1+2) + (1+3) = 8 S(3) % 2 = 0
 

Author
yifenfei
 

Source
奋斗的年代
 

Recommend
yifenfei








这个规律仔细想想还真是不算难啊,虽然想不到,凡是“能够被完全开方”或者“被2整除后能够完全被开方”的数,它的(T(N) % 2)都是1。从此我的博客里面多了一个规律的分组。

为什么会这样呢??


对于T(n),设n=2^k*p1^s1*p2^s2*...*pm^sm,则T(n)=(2^0+2^1+...+2^k)*(p1^0+p1^1+...+p1^s1)

*...*(ps^0+ps^1+...+ps^sm);
 
因为(2^0+2^1+...+2^k)%2==1始终成立,则T(n)%2的结果取决于(pi^0+pi^1+...+pi^si)%2,只要其中一

个为0,则T(n)%2==0。所以只要有一个si为

奇数时,T(n)%2==0。即n为2^k*m^2时,T(n)为1。显然n也即m^2或2*m^2时,T(n)为1。



#include<iostream>#include<cstdio>#include<cstring>using namespace std;int main(){   int T;   int n,i,j,k;   scanf("%d",&T);   while(T--)   {       scanf("%d",&n);       int num=0;       for(i=1;i<=n;i++)       {            if(i*i<=n)            num++;            if(i*i*2<=n)            num++;            if(i*i>n)            break;       }       printf("%d\n",num%2);   }    return 0;}








 

0 0