Paperfolding

https://vjudge.net/contest/387654#problem/I

算数学期望

对折和切刀都会使数量翻倍

横着切刀和上下对着效果相同,竖着切刀和左右对折效果相同

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>
#include <limits>
#include <numeric>
#include <functional>
using namespace std;
#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))

#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef char ch;
typedef double db;

const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=100+10;
const int N=1e6+10;
const int mod=1e9+7;



ll MOD = 998244353;
ll P(ll k , ll n)
{
    ll base = 1;
	k %= MOD;
    while(n)
	{
        if(n & 1)
		{
            base = base * k % MOD;
        }
        k = k * k % MOD;
		n >>= 1;
    }
    return base;
}
int main()
{
	int T = 0;
	ll n = 0 , ans = 0;
    cin >> T;
    while(T--)
	{
        cin >> n;
		
		ans = 2 * P(3 , n) % MOD;
		ll temp = P(2 , n);
        ans *= P(temp , MOD-2);
		ans %= MOD;
        ans += 1 + temp;
		ans %= MOD;
        cout << ans <<endl;
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/SutsuharaYuki/p/13460321.html