https://ac.nowcoder.com/acm/contest/331/J

C++版本一

题解:

考虑每一位,只有在(0,0)(0,1)(1,0)的三种情况时满足条件。

根据乘法原理,答案即为3^M

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int mod = 998244353;
 
ll n;
 
ll ans[105];
 
int main() {
    scanf("%lld", &n);
 
    ans[0] = 1;
    for (int i = 1; i <= 100; i++) ans[i] = ans[i - 1] * 3 % mod;
    printf("%lld\n", ans[n]);
    return 0;
}

C++版本二

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int MOD=998244353;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
int ans,cnt,flag,temp;
int a[N];
char str;
ll PowerMod(ll a, ll b, ll c){
    ll ans = 1;
        a = a % c;
    while(b>0){
        if(b % 2 == 1)
            ans = (ans * a) % c;
        b >>= 1;
        a = (a * a) % c;
    }
    return ans;
}

int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    scanf("%d",&n);
    cout << PowerMod(3,n,MOD) << endl;
    //cout << "Hello world!" << endl;
    return 0;
}