1001.Tetrahedron
1/h2 = 1/a2+1/b2+1/c2
可以算出 ans=(3∑1 / i2)/n
On预处理一下1 / i2
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, a, b) for (register int i = a; i <= b; i++) int mod = 998244353; int inv[6000010], inv2[6000010]; int n; inline void solve(int T) { cin >> n; cout << 3ll * inv2[n] * inv[n] % mod << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); inv[1] = inv2[1] = 1; rep(i, 2, 6000000) { inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod; inv2[i] = (inv2[i - 1] + (ll)inv[i] * inv[i]) % mod; } int T = 1; cin >> T; rep(i, 1, T) solve(i); }
1009.Paperfolding
横着折x次竖着折y次的分割数为 2x+2y+2x+y+1
结果的概率就表示为 (∑C(n,i)*(2i+2n-i+2n+1))/ 2n
化简就成了 3n / 2n-1+2n+1
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, a, b) for (register int i = a; i <= b; i++) ll mod = 998244353; ll ksm(ll a, ll b) { ll res = 1; for (; b; b >>= 1, a = a * a % mod) if (b & 1) res = res * a % mod; return res; } ll n; inline void solve(int T) { cin >> n; if (n == 0) puts("4"); else cout << (1ll * ksm(3, n) * ksm(499122177, n - 1) % mod + ksm(2, n) + 1) % mod << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; cin >> T; rep(i, 1, T) solve(i); }