首页 > ACM题库 > HDU-杭电 > hdu 2608 0 or 1-递推-[解题报告]C++
2014
02-12

hdu 2608 0 or 1-递推-[解题报告]C++

0 or 1

问题描述 :

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).

输入:

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.

输出:

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.

样例输入:

3
1
2
3 

样例输出:

1
0
0


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

先打表找出T[i]%2=1的i有哪些

发现规律T[i*i]=1和T[2*i*i]=1

#include<stdio.h>
#include<string.h>
int main()
{
	int i,j,n,t,sum;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
			sum=0;
			for(i=1;i<=n;i++)
			{
				
				if(2*i*i<=n)
					sum++;
				if(i*i<=n)
				sum++;
				else break;
			}
			printf("%d\n",sum%2);
	}
	return 0;
}

解题转自:http://blog.csdn.net/aixiaoling1314/article/details/8960623


  1. 学算法中的数据结构学到一定程度会乐此不疲的,比如其中的2-3树,类似的红黑树,我甚至可以自己写个逻辑文件系统结构来。

  2. 第2题,TCP不支持多播,多播和广播仅应用于UDP。所以B选项是不对的。第2题,TCP不支持多播,多播和广播仅应用于UDP。所以B选项是不对的。