题意简述
边长为 的正方形做 次分割,每次把当前右下角的那块分成 个小矩形。求最终矩形总数,对 取模。
解题思路
每次分割把一块矩形换成 块,净增 块。 次分割各自独立,矩形总数即 ,按式取模输出。注意 , 需用 位整数。
时间复杂度为 。
参考代码
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int mod=998244353;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n,k;
cin>>n>>k;
cout<<((n*n-1)%mod*(k%mod)+1)%mod<<'\n';
return 0;
}