TetrahedronHDU-6814数学的導出+前処理

[1、n]に3つの整数a、b、cを独立して等しい確率で生成し、それらを直角四面体の3つの直角辺の長さとして使用します。直角の頂点から勾配までの距離(ユークリッド距離)の逆数の二乗の期待値を見つけます。

テストケースごとに、回答mod998244353を含む行を出力します。
ここに画像の説明を挿入

入力
最初の行では、テストケースの数を示す整数Tを読み取る必要があります。

すべてのテストケースで、唯一の行には整数nが含まれます。

Tは2×106以下、nは6×106以下であることが保証されています。
出力
各テストケースについては、出力回答を示すただ一つの整数を含む行だけが998244353.国防省
サンプル入力
3
1
2
3
サンプル出力を
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;
}

おすすめ

転載: blog.csdn.net/qq_40924271/article/details/107965460