0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 15:16:28 +00:00

Compare commits

..

3 Commits

3 changed files with 122 additions and 0 deletions

42
Luogu/P2398/P2398.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
int n, phi[N];
long long sum[N], ans;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
phi[1] = 1;
for (int i = 2; i <= n; i++) {
phi[i] = i;
}
for (int i = 2; i <= n; i++) {
if (phi[i] == i) {
for (int j = i; j < N; j += i) {
phi[j] = phi[j] / i * (i - 1);
}
}
}
for (int i = 1; i <= n; i++) {
sum[i] = sum[i - 1] + phi[i];
}
for (int i = 1; i <= n; i++) {
ans += (sum[n / i] * 2 - 1) * i;
}
cout << ans << endl;
return 0;
}

31
Luogu/P3773/P3773.cpp Normal file
View File

@ -0,0 +1,31 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 233333 + 5;
const int mod = 1e9 + 7;
int n, f[N], ans;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1, x; i <= n; i++) {
cin >> x;
for (int j = x - 1 & x; j; j = j - 1 & x) {
f[j] = (f[j] + f[x] + 1) % mod;
}
ans = (ans + f[x]) % mod;
}
cout << ans << endl;
return 0;
}

49
Luogu/P4071/P4071.cpp Normal file
View File

@ -0,0 +1,49 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
int t, n, m, fac[N], inv[N], fac_inv[N], d[N];
inline int C(int n, int m) {
return static_cast<long long>(fac[n]) * fac_inv[m] % mod * fac_inv[n - m] % mod;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
fac[0] = 1;
for (int i = 1; i < N; i++) {
fac[i] = static_cast<long long>(fac[i - 1]) * i % mod;
}
inv[0] = inv[1] = 1;
for (int i = 2; i < N; i++) {
inv[i] = static_cast<long long>(mod - (mod / i)) * inv[mod % i] % mod;
}
fac_inv[0] = fac_inv[1] = 1;
for (int i = 2; i < N; i++) {
fac_inv[i] = static_cast<long long>(fac_inv[i - 1]) * inv[i] % mod;
}
d[2] = 1;
for (int i = 3; i < N; i++) {
d[i] = static_cast<long long>(i - 1) * (d[i - 1] + d[i - 2]) % mod;
}
cin >> t;
while (t--) {
cin >> n >> m;
cout << (n == m ? 1 : static_cast<long long>(d[n - m]) * C(n, m) % mod) << endl;
}
return 0;
}