[HDU] [4349] Xiao Ming's Hope

Problem Description

Loading...

Problem Analysis

The previous contest asked for
the number of odd numbers in the nth row of Pascal’s triangle
and this is essentially the same thing

A generalization of Lucas’ theorem
I referred to Yushen’s blog
hdoj 4349 Xiao Ming’s Hope (Lucas generalization)

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include<stdio.h>
int main() {
	int n;
	while(scanf("%d",&n)!=EOF) {
		int cnt=0;
		while(n) {
			if(n&1)
				cnt++;
			n>>=1;
		}
		printf("%d\n",1<<cnt);
	}
	return 0;
}

Problem link: HDU 4349 Xiao Ming’s Hope

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...