题解:P10792 『SpOI - R1』笑起来最帅的小孩
Description
给定序列
Analysis
设
由于插入位置随机,
总时间复杂度
Code
#include"bits/stdc++.h"
#define int long long
using namespace std;
const int N = 1e5 + 5, mod = 2007072007;
int t, k;
int fpow(int a, int b) {
int re = 1;
while (b) {
if (b & 1)
re = (__int128)re * a % mod;
a = (__int128)a * a % mod;
b >>= 1;
}
return re;
}
signed main() {
cin >> t;
while (t--) {
cin >> k;
int s = 0, n = 0;
for (int i = 1, x, l; i <= k; i++) {
cin >> x >> l;
s += x * l;
n += l;
}
__int128 ans = s;
ans = ans * (fpow(10, n) - 1) % mod;
ans = (ans % mod + mod) % mod;
ans = ans * fpow(n, mod - 2) % mod * fpow(9, mod - 2) % mod;
cout << (int)ans << '\n';
}
return 0;
}