Problem Description
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.
Input
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.
Output
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从[1,n]随机挑选,求三者交点到底面的距离的平方的逆元的期望。
思路:1/(h2)=1/(a2)+1/(b2)+1/(c2)所以期望是E(1/h2)=E(1/a2)+E(1/b2)+E(1/c2)=3*E(1/a2),打表输出就行,然后这题还卡输入输出,恶心
代码:
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
typedef long long ll;
const int N = 6e6 + 5;
ll num[N];
ll quick_pow(ll a, ll b)
{
ll ans = 1;
while (b)
{
if (b & 1)
ans = (ans*a) % mod;
b >>= 1;
a = (a*a) % mod;
}
return ans;
}
void inv()
{
for (ll i = 1; i <= 6e6; i++)
{
num[i] = quick_pow(i*i%mod, mod - 2);
num[i] = (num[i] + num[i - 1]) % mod;
}
}
int main()
{
inv();
int T;
scanf("%d", &T);
while (T--)
{
ll n;
scanf("%lld", &n);
printf("%lld\n", 3 * num[n] * quick_pow(n, mod - 2) % mod);
}
}