HDU6814 Tetrahedron(几何/数论/逆元)
Generate three integers , , and in 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 .

Input
In the first line, you should read an integer denoting the number of test cases.
In every test case, the only line will include an integer .
It is guaranteed that is no larger than and is no larger than .
Output
For each test case, output the only line containing just one integer denoting the answer mod .
Sample Input
3
1
2
3
Sample Output
3
124780546
194103070
题意是从1~n等概率任选3个数,求以这三个数为直角边构成的直角三棱锥中直角顶点到斜平面的距离平方的倒数的期望。
由高中数学可得有公式,这个可以设出来三条边然后根据海伦公式推。那么最终要求的期望E就为
然后预处理出1~6e6的的前缀和,查询的时候直接输出即可。但这里还有取模操作,分数取模用到费马小定理,,用快速幂搞一下就好了。
重点中的重点:后也要取模!WA了15发就是没注意....
#include <bits/stdc++.h>
#define mod 998244353
typedef long long ll;
using namespace std;
long long ans[6000005];
long long ksm(long long x,long long y){
long long a=1;
while(y){
if(y&1) a=a*x%mod;
y>>=1;
x=x*x%mod;
}
return a;
}
int main()
{
//freopen("A.in","r",stdin);
//freopen("my.out","w",stdout);
int t;
cin >> t;
ans[1] = 1;
for(long long i = 2; i <= 6000005; i++)
{
ans[i] = ksm(i * i % mod, mod-2) % mod;
ans[i] = (ans[i - 1] % mod + ans[i] % mod) % mod;
}
while(t--)
{
long long n;
scanf("%lld", &n);
printf("%lld\n", ans[n] * 3 * ksm(n , mod-2) % mod);
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!