多少岁月想要伴你走过 燕回春野蝉鸣夏夜说予我
dovely_seele · · 题解
可能我阅读理解能力不太好,没看懂其他题解(
首先根据等比数列求和公式
首先考虑只有两个数的情况,这时 lcm 也就是乘积除以 gcd。 根据具体数学习题 4.38,
首先显然
现在如果换成多个数如何求 lcm 呢?两个数取 lcm 之后已经不是
我们用 map 维护一个集合中所有子集中每个 gcd 的出现次数(由于 gcd 也是
说的不太清楚,看代码吧。
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
map<long long, long long> s, seele;
long long qp(long long n, long long m, long long p) {
long long ans = 1, base = n;
while (m) {
if (m & 1) (ans *= base) %= p;
(base *= base) %= p; m >>= 1;
}
return ans;
}
int main() {
long long x, n, t, prod=1; cin>> x>> n; x %= (long long)(1e9+7); for (int i=1; i<=n; i++) {
cin>> t; ++t; seele.clear(); for (auto it: s) seele[it.first] = it.second; for (auto it : seele) s[__gcd(it.first, t)] -= it.second; s[t]++;
} for (auto it: s) (prod *= it.second> 0?qp(qp(x, it.first, 1e9+7) - 1, it.second, 1e9+7): qp(qp(qp(x, it.first, 1e9+7) - 1, -it.second, 1e9+7), 1e9+5, 1e9+7)) %= (long long)(1e9+7); cout << prod * qp(x-1, 1e9+5, 1e9+7) % (long long)(1e9+7);
}