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
**题意:**正四面体内求1/h^2的数学期望
分析:
**注意:**因为数据量过大,直接循环暴力求解会T,所以我们需要进行预处理,同时由于我们还需要对答案进行取余处理,但是计算又涉及分数的取余,所以我们要进行求逆元。
AC代码如下:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iomanip>
#include<map>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<set>
#include<cctype>
#include<string>
#include<stdexcept>
#include<fstream>
#include<sstream>
#define mem(a,b) memset(a,b,sizeof(a))
#define debug() puts("what the fuck!")
#define dedebug() puts("what the fuck!!!")
#define ll long long
#define ull unsigned long long
#define speed {ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); };
using namespace std;
const double PI = acos(-1.0);
const int maxn = 6e6 + 50;
const int N = 110;
const int INF = 0x3f3f3f3f;
const int inf = 0xfffffff;//比INF小,防止累加爆int
const double esp_0 = 1e-6;
const double gold = (1 + sqrt(5)) / 2;
const int mod = 998244353;
int gcd(int x, int y) {
return y ? gcd(y, x % y) : x;
}
ll fastpow(ll a, ll b){//快速幂
ll ans = 1;
while (b) {
if (b & 1) ans = (ans * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return ans;
}
ll inv(ll a, ll b){//分数取余(逆元)
return (a * fastpow(b, mod - 2)) % mod;
}
ll sum[maxn];
void init() {
mem(sum, 0);
for (ll i = 1; i < maxn; ++i) {//遍历定义为ll 这里wrong了好多发 定义函数参数为ll
sum[i] = (sum[i - 1] + inv(1, (i * i) % mod)) % mod;
}
}
ll n;
int main() {
init();
int t;
scanf("%d", &t);
while (t--) {
scanf("%lld", &n);
printf("%lld\n", (3ll * sum[n] * inv(1, n)) % mod);
}
return 0;
}