Please calculate the coefficient modulo 2 of x^i in (1+x)^n.
Input
For each case, there are two integers n, i (0<=i<=n<=2^31-1)
Output
For each case, print the coefficient modulo 2 of x^i in (1+x)^n on a single line.
Sample Input
3 1 4 2
Sample Output
1 0
我自己想不出来,只能是没听过这个知识点,判断C(n,i)的奇偶性,如果它是奇数就满足(n&i)==i
#include<iostream>
using namespace std;
int main()
{
int n,i;
while(cin>>n>>i)
{
if((n&i)==i)
cout<<1<<endl;
else
cout<<0<<endl;
}
return 0;
}