Tetrahedron HDU - 6814 数学推导+预处理

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值