Description
求组合数 C ( n , k) 的奇偶性Input
文件是多case的,每行输入一个 n (1<=n<=10^9)和 k(0<=k<=n) ,当 n 等于 0 且 k 等于 0 时输入结束Output
对于每一个case,输出一行,为组合数 C ( n , k) 的奇偶性,奇输出1,偶输出0Sample Input
2 0 2 1 0 0Sample Output
1 0Author
windy7926778
#include<iostream> #include<cmath> using namespace std; long long get( long long n ) { long long two = 2; long long num = 0; while(n >= two) { num += n / two; two *= two; } return num; } int main() { long long n, k; while(cin >> n >> k&&n) { if(k == 0) { cout << 1 << endl; } else { long long num = get( n ) - get( n-k ) -get(k); cout << (num == 0 ? 1 : 0) << endl; } } return 0; }
原文地址:http://blog.csdn.net/maxichu/article/details/45594831