题目描述:
Generate three integers a, b, and c in [1,n] with equal probability independently, and use them as the three right-angle side length of a right-angled tetrahedron. Find the expectation of the reciprocal square of the distance from the right-angle apex to the slope (Euclidean distance).
For each test case, output a line containing the answer mod 998244353.
输入
In the first line, you should read an integer T denoting the number of test cases.
In every test case, the only line will include an integer n.
It is guaranteed that T is no larger than 2×106 and n is no larger than 6×106.
输出
For each test case, output the only line containing just one integer denoting the answer mod 998244353.
Sample Input
3
1
2
3
Sample Output
3
124780546
194103070
由于a, b, c三边实际上是轮换对称的, 因此求期望的时候可以令a = b = c = x;
根据等面积法,a * b * c / 6 = x ^ 3 / 6 = V = (sqrt(3) / 4) * (sqrt(2) * x) ^ 2 * h / 3
得 1 / h ^ 2 = 3 / x ^ 2
而x ∈ [1, n],x ∈ Z,所以 E(n) = (3 / 1 ^ 2 + 3 / 2 ^ 2 + 3 / 3 ^ 2 + ··· + ·3 / n ^ 2)/ n;
(由于没有看见x ∈ Z这个条件,导致一直做不出来。。。。。。)
代码如下
//Siberian Squirrel
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define print(x) printf("%d\n", x)
typedef long long ll;
const double PI = acos(-1);
const int inf = 0x3f3f3f3f, MAXN = 6e6+10, MOD = 998244353;
inline int read() {
int res = 0;
char c = getchar();
while (!isdigit(c)) c = getchar();
while (isdigit(c)) res = (res << 1) + (res << 3) + (c ^ 48), c = getchar();
return res;
}
//
ll a[MAXN] = {1, 1};
int T, n;
//
inline ll quick_pow(ll ans, ll p, ll mod, ll res = 1) {
ans %= mod;
for (; p; p >>= 1, ans = (ans % MOD * ans % mod) % MOD)
if (p & 1) res = ((res % MOD * ans % mod) % MOD);
return res % mod;
}
inline int inv2(ll res, ll mod) {
return quick_pow(res, mod - 2, mod);
}
void pre() {
for(int i = 2; i < MAXN; ++i) {
a[i] = (a[i - 1] + inv2(1ll * i * i % MOD, MOD)) % MOD;
}
}
int main() {
pre();
T = read();
while(T--) {
n = read();
printf("%lld\n", ((a[n] * 3 % MOD) + MOD) * inv2(n, MOD) % MOD);
}
}