2020 Multi-University Training Contest 5 —— Tetrahedron

题目描述:

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值