组合数问题

组合数问题

https://ac.nowcoder.com/acm/contest/9986/F

思路

代码

// Problem: 组合数问题
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/9986/F
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp(aa,bb) make_pair(aa,bb)
#define _for(i,b) for(int i=(0);i<(b);i++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,b,a) for(int i=(b);i>=(a);i--)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define X first
#define Y second
#define lowbit(a) (a&(-a))
#define debug(a) cout<<#a<<":"<<a<<"\n"
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef long double ld;
const int N=100010;
const int INF=0x3f3f3f3f;
const int mod=998244353;
const double eps=1e-6;
const double PI=acos(-1.0);

ll fpow(ll a,ll b){
    if(mod==1) return 0;
    ll ans=1%mod;
    while(b){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}

void solve(){
    ll n;cin>>n;
    ll m=n/4;
    if(m&1){
        ll ans=fpow(4,m*2-1)-fpow(2,m*2-1);ans%=mod;
        cout<<(ans+mod)%mod<<"\n";
    }
    else{
        ll ans=(fpow(2,m*2-1)+fpow(4,m*2-1))%mod;
        cout<<ans<<"\n";
    }
}


int main(){
    ios::sync_with_stdio(0);cin.tie(0);
//    int t;cin>>t;while(t--)
    solve();
    return 0;
}
全部评论
这个是我找规律找出来的,%%%,STO
1 回复 分享
发布于 2021-02-24 19:17
推出来了一个和答案不一样的公式 if n % 8 == 0: 2^(n-2) + (2, n/2 - 1) else: 2^(n-2) - (2, n/2 - 1)
点赞 回复 分享
发布于 2021-02-24 18:30
oeis绝了
点赞 回复 分享
发布于 2021-02-24 18:06

相关推荐

11-13 14:37
门头沟学院 Java
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务