多校第五场——1001 Tetrahedron

本文探讨了一种算法,用于解决直角四面体中从顶点到底面距离平方逆元的期望计算问题。通过独立均匀地选取三个整数作为直角四面体的边长,算法计算了此距离逆元期望值,并提供了模998244353的解答。

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);
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值