Matrix
题目链接
题意 :
用[[1,n^2]的数填n∗n的矩阵,每个数字只能用一次,记a i 表示第i 行的最小值
.S=a1,a2,…,an∩1,2,…,n…
求∑∣S∣
思路 :
AC代码 :
#include <iostream>
#include <map>
#include <cstring>
#include <algorithm>
#include <math.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
#define ll long long
const ll maxn = 2e7 + 5e6 + 10;
const int mod = 998244353;
ll fac[maxn];
ll qpow(ll a, ll b, ll p)
{
ll ans = 1;
while (b)
{
if (b & 1)
ans = ans * a % p;
a = a * a % p;
b >>= 1;
}
return ans;
}
void init()
{
fac[0] = 1;
for (int i = 1; i < maxn; i++)
{
fac[i] = fac[i - 1] * i % mod;
}
}
ll infac(ll x)
{
return qpow(x, mod - 2, mod);
}
ll C(ll n, ll m)
{
if (n < m)
return 0;
return fac[n] * infac(fac[m]) % mod * infac(fac[n - m]) % mod;
}
void solve()
{
ll n;
scanf("%lld", &n);
ll ans = n * fac[n] % mod * fac[n * n - n] % mod;
ll sum = 0;
for (int i = 1; i <= n; i++)
{
sum += C(n * n - i, n - 1);
sum = sum % mod;
}
printf("%lld\n", ans * sum % mod);
}
int main()
{
init();
int t = 1;
scanf("%d", &t);
while (t--)
{
solve();
}
return 0;
}