HDU 4349 Xiao Ming's Hope 2012 Multi-University Training Contest 5

题意:给定n ,求n 的组合数中,奇数的个数

数论水题,打表找规律的

 

#include <stdio.h>

int main()
{
	int n,sum,i;
	while(scanf("%d",&n)!=EOF)
	{
		if(n%2!=0)
		{
			sum=0;
			for(i=0;i<=n/2;i++)
			{
				if((n&i)==i)
					sum++;
			}
			sum*=2;
		}
		else
		{
			sum=0;
			for(i=0;i<n/2;i++)
			{
				if((n&i)==i)
					sum++;
			}
			sum*=2;
			if((n&(n/2))==(n/2))
				sum++;
		}
		printf("%d\n",sum);
	}
	return 0;
}


 

你可能感兴趣的:(HDU 4349 Xiao Ming's Hope 2012 Multi-University Training Contest 5)