4413: 小粉刷匠
Submit your solution Discuss this problem Best solutions |
id="main" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="500" src="http://cstest.scu.edu.cn/soj/problem/4413" style="height: 987px;"> |
链接:点击打开链接http://cstest.scu.edu.cn/soj/problem.action?id=4413
题解:C(k,0)+C(k,1)+C(k,2)+...C(k,k)=2^k. 所以C(k,0)+C(k,2)+C(k,4)+...C(k,2*(k/2))=2^(k-1).
然后我们知道从k中取偶数个作为红,绿,就是后者,然后分别乘上偶数个作红绿,其他作黄蓝的组合数,这两个组合数公式可以合并,但是要注意处理C(k,0)的情况。要加上一半的2^K。
最后输出%lld才能AC。%I64d不能AC也是醉了。
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#define maxn 100010
typedef long long LL;
LL m,n,p;
LL Pow(LL a,LL b,LL mod){
LL ans=1;
while(b){
if(b&1) ans=(ans*a)%mod;
b>>=1;
a=(a*a)%mod;
}
return ans;
}
int main(){
int t;
scanf("%d",&t);
p=10007;
LL k;
while(t--){
scanf("%lld",&k);
LL ans=(Pow(2,2*k-2,p)+Pow(2,k-1,p))%p;
printf("%lld\n",ans);
}
return 0;
}