这题有什么规律 Description Could you tell me the coefficient of x^k in (1+x)^n is odd or even?Input The first line of the input contains a integer T,indicate the number of test cases.For each case,there are two integers n,k (0 楼下能再讲

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/04 04:52:43
这题有什么规律 Description Could you tell me the coefficient of x^k in (1+x)^n is odd or even?Input The first line of the input contains a integer T,indicate the number of test cases.For each case,there are two integers n,k (0 楼下能再讲

这题有什么规律 Description Could you tell me the coefficient of x^k in (1+x)^n is odd or even?Input The first line of the input contains a integer T,indicate the number of test cases.For each case,there are two integers n,k (0 楼下能再讲
这题有什么规律
Description
Could you tell me the coefficient of x^k in (1+x)^n is odd or even?
Input
The first line of the input contains a integer T,indicate the number of test cases.
For each case,there are two integers n,k (0
楼下能再讲讲吗?

这题有什么规律 Description Could you tell me the coefficient of x^k in (1+x)^n is odd or even?Input The first line of the input contains a integer T,indicate the number of test cases.For each case,there are two integers n,k (0 楼下能再讲
这个是牛顿二项式定理的内容.
楼上说的不错.
其实你可以直接转化为排列组合就行了:
3 1,表示3个人里选1个人,判断选人的方法数是奇数还是偶数.
4 2,表示4个人里选2个人,判断选人的方法数是奇数还是偶数.
C(3,1)=3,奇数.C(4,2)=6,偶数.
其实就是让你求C(n,k)%2是==1,还是==0?
由于k和n很大,你就要用下面这种公式:
(A/B)%K=(A%(B*K))/B;
(A*B)%K=((A%K)*(B%K))%K;

牛顿二项式定理可以递归实现,判断奇偶性直接除2取余