8.7
AT_abc020_D
直接拆开
直接枚举
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;
int n, k;
unordered_map<int, int> mp;
int calc(int x) {
return (x + 1) * x / 2 % mod;
}
int mu(int x) {
if (mp.count(x))
return mp[x];
int ans = 1, tmp = x;
for (int i = 2; i * i <= x; i++)
if (x % i == 0) {
int cnt = 0;
while (x % i == 0)
x /= i, cnt++;
if (cnt > 1)
return 0;
ans = -ans;
}
if (x > 1)
ans = -ans;
mp[tmp] = ans;
return ans;
}
int S(int x, int y) {
int ans = 0;
for (int i = 1; i * i <= y; i++)
if (y % i == 0) {
ans = (ans + mu(i) * i % mod * calc(x / i) % mod + mod) % mod;
if (i * i != y)
ans = (ans + mu(y / i) * (y / i) % mod * calc(x / (y / i)) % mod + mod) % mod;
}
return ans;
}
signed main() {
cin >> n >> k;
int ans = 0;
for (int i = 1; i * i <= k; i++)
if (k % i == 0) {
ans = (ans + S(n / i, k / i)) % mod;
if (i * i != k)
ans = (ans + S(n / (k / i), i)) % mod;
}
cout << ans * k % mod;
return 0;
}
P2231
首先转化一下题意,可以理解为从
可以得到不定方程
那么根据裴蜀定理,只有当
那么答案即为
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m;
unordered_map<int, int> mp;
int mu(int x) {
if (mp.count(x))
return mp[x];
int ans = 1, tmp = x;
for (int i = 2; i * i <= x; i++)
if (x % i == 0) {
int cnt = 0;
while (x % i == 0)
x /= i, cnt++;
if (cnt > 1)
return 0;
ans = -ans;
}
if (x > 1)
ans = -ans;
mp[tmp] = ans;
return ans;
}
int fpow(int a, int b) {
int res = 1;
while (b) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
signed main() {
cin >> n >> m;
int ans = 0;
for (int i = 1; i * i <= m; i++)
if (m % i == 0) {
ans += mu(i) * fpow(m / i, n);
if (i * i != m)
ans += mu(m / i) * fpow(i, n);
}
cout << ans;
return 0;
}
CF235E
根据P3227,我们可以扩展得到
所以,将其代入原式,并同时使用莫比乌斯反演得到
注意到
则原式变为
预处理
P10584
首先,任意正整数
则
所以我们枚举
-
1 \le x \le \lfloor \sqrt{\frac{n}{d}} \rfloor -
1 \le y \le \lfloor \sqrt{\frac{m}{d}} \rfloor
所以答案为
恒等式
所以,答案又变为
定义:
代入式子化简为
双重整除分块+线性筛求出即可。