数学综合练习
综合练习
AT_abc020_d [ABC020D] LCM Rush
:::success[代码]
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int M = 1e9 + 7;
LL n, m;
unordered_map<LL, LL> u;
LL C(LL n) {
LL s = 1;
for (LL i = 2; i * i <= n; i++) {
if (n % i) continue;
LL c = 0;
for (s = -s; !(n % i); n /= i, c++);
if (c > 1) return 0;
}
return (n > 1 ? -s : s);
}
LL V(LL n) {
return n * (n + 1) / 2 % M;
}
LL W(LL k) {
LL s = 0;
for (LL i = 1; i * i <= k; i++) {
auto C = [&](LL x) { return u[x] * x * V(n * k / (m * x)) % M + M; };
!(k % i) && (s = (s + C(i)) % M, i != k / i && (s = (s + C(k / i)) % M));
}
return s;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for (LL i = 1; i * i <= m; i++) {
!(m % i) && (u[i] = C(i), u[m / i] = C(m / i));
}
LL s = 0;
for (LL i = 1; i * i <= m; i++) {
!(m % i) && (s = (s + W(i)) % M, i != m / i && (s = (s + W(m / i)) % M));
}
cout << s * m % M;
return 0;
}
:::
P2231 [HNOI2002] 跳蚤
可以列出不定方程
由裴蜀定理,有
则
:::success[代码]
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL n, m, s;
LL P(LL x, LL y) {
LL s = 1;
for (; y; x *= x, y >>= 1) y & 1 && (s *= x);
return s;
}
LL C(LL n) {
LL s = 1;
for (LL i = 2; i * i <= n; i++) {
if (n % i) continue;
LL c = 0;
for (s = -s; !(n % i); n /= i, c++);
if (c > 1) return 0;
}
return (n > 1 ? -s : s);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for (LL i = 1; i * i <= m; i++) {
auto V = [](LL x) { return C(x) * P(m / x, n); };
!(m % i) && (s += V(i), i != m / i && (s += V(m / i)));
}
cout << s;
return 0;
}
:::
CF235E Number Challenge
类似于 P3327,有一个拆分公式
代入,有
设
从而
将
:::success[代码]
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL N = 2005, M = 1073741824;
LL a, b, c, n, u[N], v[N][N];
LL lcm(LL a, LL b) {
return a / __gcd(a, b) * b;
}
LL U(LL n) {
LL s = 1;
for (LL i = 2; i * i <= n; i++) {
if (n % i) continue;
LL c = 0;
for (s = -s; !(n % i); n /= i, c++);
if (c > 1) return 0;
}
return (n > 1 ? -s : s);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> a >> b >> c;
n = max({a, b, c});
for (int i = 1; i <= n; i++) {
u[i] = U(i);
for (int j = 1; j <= i; j++) {
for (int k = 1; k <= i / j; k++) {
v[i][j] = (v[i][j] + i / (j * k)) % M;
}
}
}
LL s = 0, x, y, z;
for (int i = 1; i <= a; i++) {
if (!u[i]) continue;
for (int j = 1; j <= b; j++) {
if (!u[j] || (y = lcm(i, j)) > b) continue;
for (int k = 1; k <= c; k++) {
if (!u[k] || (x = lcm(i, k)) > a || (z = lcm(j, k)) > c) continue;
s = (s + u[i] * u[j] * u[k] * v[a][x] * v[b][y] % M * v[c][z] % M + M) % M;
}
}
}
cout << s;
return 0;
}
:::
P10584 [蓝桥杯 2024 国 A] 数学题
任意正整数
则
因此,设
-
\displaystyle 1 \le d \cdot x ^ 2 \le n \implies 1 \le x \le \left\lfloor \sqrt{\frac n d} \right\rfloor -
\displaystyle 1 \le d \cdot y ^ 2 \le n \implies 1 \le y \le \left\lfloor \sqrt{\frac m d} \right\rfloor
则
有一个神奇的恒等式
直接计算
定义子问题
式子进一步化简为:
用线性筛和整除分块处理即可。
:::success[代码]
zrr
:::