-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2182 - Divisor Analysis.cpp
More file actions
58 lines (48 loc) · 1.32 KB
/
2182 - Divisor Analysis.cpp
File metadata and controls
58 lines (48 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
const ll mod = 1e9 + 7;
ll binpow(ll a, ll b, ll mod = mod) {
if (b == 0) return 1;
auto tmp = binpow(a, b / 2, mod);
if (b & 1)
return (tmp * tmp % mod) * a % mod;
else
return tmp * tmp % mod;
}
ll inv(ll a) { return binpow(a, mod - 2, mod); }
void solve() {
int n;
cin >> n;
vector<pll> a(n);
for (auto &i : a) cin >> i.first >> i.second;
// num is the number of divisors mod 1e9+7
ll num = 1, sum = 1, prod = 1;
for (auto [p, k] : a) {
num *= (k + 1) % mod, num %= mod;
sum *= (binpow(p, k + 1) - 1) * inv(p - 1) % mod, sum %= mod;
}
;
vector<ll> precompute(n);
for (ll i = 0, num2 = 1; i < n; i++) {
auto [p, k] = *(a.begin() + i);
precompute[i] =
binpow(p, num2 * (k * (k + 1) / 2 % (mod - 1)) % (mod - 1));
num2 *= (k + 1) % (mod - 1), num2 %= mod - 1;
}
for (ll i = n - 1, num2 = 1; i >= 0; i--) {
auto [p, k] = *(a.begin() + i);
prod *= binpow(precompute[i], num2), prod %= mod;
num2 *= (k + 1) % (mod - 1), num2 %= mod - 1;
}
cout << num << " " << sum << " " << prod << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
}