当前位置: 移动技术网 > 移动技术>移动开发>IOS > 2020多校第五场Paperfolding

2020多校第五场Paperfolding

2020年08月10日  | 移动技术网移动技术  | 我要评论

思路

将折痕分为竖直和水平,分别考虑。对折n次,有2^n-1贡献,结合二次项定理将公式进行化简。

代码

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>

#define ll long long
using namespace std;
const int maxn=6e6+6;
const ll mod=998244353;
const ll MOD=998244353;

ll power(ll x,ll a)
{
    ll ans=1;
    while(a)
    {
        if(a&1)
        {
            ans=ans*x%mod;
        }
        x=x*x%mod;
        a>>=1;
    }
    return ans;
}
int main()
{
    std::ios::sync_with_stdio(false);cin.tie(0);

    int T;cin>>T;
    while(T--)
    {
        ll n;
        cin>>n;
        ll k = power(2,n);
        ll inv = power(k,mod-2);
        ll ans = 1 + power(2,n) + power(3,n) * inv * 2 % mod;
        cout<<ans%mod<<endl;
    }
    return 0;
}

本文地址:https://blog.csdn.net/CreatureNoWords/article/details/107900195

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网