题目链接:H-Hile and Subsequences' MEX_2021年浙大城市学院新生程序设计竞赛(同步赛) (nowcoder.com)
这个是一个规律题,表面上的规律是n + (n - i) * pow(2, i),
但是这个过于暴力,通过值和n的关系可以求出是pow(2, n) - 1
快速幂可以解决
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 998244353
ll power(ll n, ll a){
ll temp = 1;
if(a == 0){
return 1;
}
while(a){
if(a & 1){
temp *= n;
temp %= N;
}
a /= 2;
n *= n;
n %= N;
}
return temp;
}
int main(){
int t;
cin >> t;
int n;
ll sum;
while(t--){
cin >> n;
ll a = power(2, n) - 1;
a += N;
a %= N;
cout << a << endl;
}
return 0;
}