列举前几项,易发现答案为斐波那契数列前m项求和
#include <iostream>
using namespace std;
int main() {
long long m, a = 1, b = 2, ans = 3;
const long long M = 998244353;
cin >> m;
if (m == 1) {
cout << 1;
return 0;
} else if (m == 2) {
cout << 3;
return 0;
}
while (m > 2) {
b = a + b;
a = b - a;
b %= M;//取模防止数据超限
ans += b;
ans %= M;
--m;
}
cout << ans;
}
b %=M;