牛客寒假算法基础训练营6 F.组合数问题
作者:互联网
传送门
思路:Cn0+Cn1+Cn2+…=2 ^ n=(1+1)^n
Cn0-Cn1+Cn2+…=(1-1)^n
将上面两式相加
得到Cn0+Cn2+…=2^n-1
且
从而得出答案
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 998244353;
ll qpow(ll a,ll b)
{
ll ans = a%mod;
ll sum = 1;
while(b)
{
if(b&1)
sum = sum*ans%mod;
ans = ans*ans%mod;;
b /=2;
}
return sum%mod;
}
int main()
{
ll n;
scanf("%lld",&n);
ll m = n/4;
if(m%2)
{
ll ans = qpow(4,m*2-1) - qpow(2, m*2-1);
ans = (ans + mod)%mod;
printf("%lld\n",(ans+mod)%mod);
}
else
{
printf("%lld\n",(qpow(2, m*2-1)%mod + qpow(4, m*2-1)%mod)%mod);
}
}
标签:qpow,Cn2,训练营,牛客,寒假,ans,lld,ll,mod 来源: https://blog.csdn.net/p15008340649/article/details/114151442