和平战争 题解
littlesnake · · 题解
和平战争 传送门
很明显这是不停地在
- 如果
t 是偶数,指数等于6^{\frac{t}{2}} 。 - 如果
t 是奇数,指数等于6^{\frac{t}{2}} \times 3 (当然这里的除法是下取整)。
那么我们可以做对
# include <bits/stdc++.h>
# define ll long long
# define p 998244353
using namespace std;
ll z, t, zs;
ll qpow (ll x, ll y) {
x %= p;
ll res = 1;
while (y) {
if (y & 1) res = (res * x) % p;
x = (x * x) % p;
y >>= 1;
}
return res % p;
}
int main () {
ios::sync_with_stdio (0);
cin.tie (0), cout.tie (0);
cin >> z >> t;
if (t % 2 == 0) zs = qpow (6, t / 2) % p;
else zs = qpow (6, t / 2) * 3 % p;
cout << qpow (z, zs) % p;
return 0;
}