mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-14 03:58:48 +00:00
Compare commits
4 Commits
74f9851e31
...
826377f687
Author | SHA1 | Date | |
---|---|---|---|
826377f687 | |||
e318a6bac2 | |||
6fcc52aaf7 | |||
3a9f733349 |
51
LibreOJ/2599/2599.cpp
Normal file
51
LibreOJ/2599/2599.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 1005;
|
||||||
|
const int mod = 1e4 + 7;
|
||||||
|
|
||||||
|
int a, b, k, n, m;
|
||||||
|
int fac[N], inv[N];
|
||||||
|
|
||||||
|
int binpow(int a, int b) {
|
||||||
|
int res = 1;
|
||||||
|
a %= mod;
|
||||||
|
while (b) {
|
||||||
|
if (b & 1) res = static_cast<long long>(res) * a % mod;
|
||||||
|
a = static_cast<long long>(a) * a % mod;
|
||||||
|
b >>= 1;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int C(int n, int m) {
|
||||||
|
return static_cast<long long>(fac[n]) * inv[m] % mod * inv[n - m] % mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
fac[0] = 1;
|
||||||
|
for (int i = 1; i <= 1000; i++) {
|
||||||
|
fac[i] = static_cast<long long>(fac[i - 1]) * i % mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
inv[0] = inv[1] = 1;
|
||||||
|
for (int i = 2; i <= 1000; i++) {
|
||||||
|
inv[i] = static_cast<long long>(mod - (mod / i)) * inv[mod % i] % mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 2; i <= 1000; i++) {
|
||||||
|
inv[i] = static_cast<long long>(inv[i - 1]) * inv[i] % mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
cin >> a >> b >> k >> n >> m;
|
||||||
|
|
||||||
|
cout << static_cast<long long>(C(k, n)) * binpow(a, n) % mod * binpow(b, m) % mod << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
LibreOJ/2599/data/factor1.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor1.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor1.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor10.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor10.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor10.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor2.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor2.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor2.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor3.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor3.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor3.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor4.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor4.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor4.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor5.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor5.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor5.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor6.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor6.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor6.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor7.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor7.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor7.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor8.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor8.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor8.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor9.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor9.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2599/data/factor9.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2599/data/factor9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
79
Luogu/P1306/P1306.cpp
Normal file
79
Luogu/P1306/P1306.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 10;
|
||||||
|
const int mod = 1e8;
|
||||||
|
|
||||||
|
class Matrix {
|
||||||
|
private:
|
||||||
|
long long data[N][N];
|
||||||
|
|
||||||
|
public:
|
||||||
|
Matrix() {
|
||||||
|
memset(data, 0x00, sizeof(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
long long* operator[](int i) {
|
||||||
|
return data[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix operator*(Matrix b) const {
|
||||||
|
Matrix c;
|
||||||
|
|
||||||
|
int n = 2;
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
for (int j = 1; j <= n; j++) {
|
||||||
|
for (int k = 1; k <= n; k++) {
|
||||||
|
c[i][j] = (c[i][j] + data[i][k] * b[k][j] % mod) % mod;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
} base, ans;
|
||||||
|
|
||||||
|
Matrix binpow(Matrix a, int k) {
|
||||||
|
Matrix res;
|
||||||
|
res[1][1] = 1;
|
||||||
|
res[1][2] = 1;
|
||||||
|
|
||||||
|
while (k) {
|
||||||
|
if (k & 1) res = res * a;
|
||||||
|
a = a * a;
|
||||||
|
k >>= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
long long fib(int n) {
|
||||||
|
if (n <= 2) {
|
||||||
|
return !!n;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix tmp;
|
||||||
|
|
||||||
|
tmp[1][1] = 1, tmp[1][2] = 1;
|
||||||
|
tmp[2][1] = 1, tmp[2][2] = 0;
|
||||||
|
|
||||||
|
return binpow(tmp, n - 2)[1][1];
|
||||||
|
}
|
||||||
|
|
||||||
|
int n, m;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
|
||||||
|
cin >> n >> m;
|
||||||
|
|
||||||
|
cout << fib(std::__gcd(n, m)) % mod << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <array>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
using std::cin;
|
using std::cin;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
@ -7,8 +9,57 @@ const char endl = '\n';
|
|||||||
const int N = 1005;
|
const int N = 1005;
|
||||||
const int mod = 1e4 + 7;
|
const int mod = 1e4 + 7;
|
||||||
|
|
||||||
|
template <int x>
|
||||||
|
using number = std::integral_constant<int, x>;
|
||||||
|
|
||||||
|
template <int n>
|
||||||
|
struct factorial : number<static_cast<long long>(n) * factorial<n - 1>::value % mod> {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct factorial<0> : number<1> {};
|
||||||
|
|
||||||
|
template <int... S>
|
||||||
|
constexpr std::array<int, sizeof...(S)> get_factorial_table_impl(std::integer_sequence<int, S...>) {
|
||||||
|
return {factorial<S>::value...};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <int S>
|
||||||
|
constexpr auto get_factorial_table() {
|
||||||
|
return get_factorial_table_impl(std::make_integer_sequence<int, S>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
template <int n>
|
||||||
|
struct inverse : number<static_cast<long long>(mod - (mod / n)) * inverse<mod % n>::value % mod> {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct inverse<1> : number<1> {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct inverse<0> : number<1> {};
|
||||||
|
|
||||||
|
template <int n>
|
||||||
|
struct factorial_inverse : number<static_cast<long long>(factorial_inverse<n - 1>::value) * inverse<n>::value % mod> {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct factorial_inverse<1> : number<1> {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct factorial_inverse<0> : number<1> {};
|
||||||
|
|
||||||
|
template <int... S>
|
||||||
|
constexpr std::array<int, sizeof...(S)> get_factorial_inverse_table_impl(std::integer_sequence<int, S...>) {
|
||||||
|
return {factorial_inverse<S>::value...};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <int S>
|
||||||
|
constexpr auto get_factorial_inverse_table() {
|
||||||
|
return get_factorial_inverse_table_impl(std::make_integer_sequence<int, S>{});
|
||||||
|
}
|
||||||
|
|
||||||
int a, b, k, n, m;
|
int a, b, k, n, m;
|
||||||
int fac[N], inv[N];
|
|
||||||
|
constexpr auto fac = get_factorial_table<N>(),
|
||||||
|
inv = get_factorial_inverse_table<N>();
|
||||||
|
|
||||||
int binpow(int a, int b) {
|
int binpow(int a, int b) {
|
||||||
int res = 1;
|
int res = 1;
|
||||||
@ -29,20 +80,6 @@ int main() {
|
|||||||
std::ios::sync_with_stdio(false);
|
std::ios::sync_with_stdio(false);
|
||||||
cin.tie(nullptr);
|
cin.tie(nullptr);
|
||||||
|
|
||||||
fac[0] = 1;
|
|
||||||
for (int i = 1; i <= 1000; i++) {
|
|
||||||
fac[i] = 1ll * fac[i - 1] * i % mod;
|
|
||||||
}
|
|
||||||
|
|
||||||
inv[0] = inv[1] = 1;
|
|
||||||
for (int i = 2; i <= 1000; i++) {
|
|
||||||
inv[i] = static_cast<long long>(mod - (mod / i)) * inv[mod % i] % mod;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 2; i <= 1000; i++) {
|
|
||||||
inv[i] = static_cast<long long>(inv[i - 1]) * inv[i] % mod;
|
|
||||||
}
|
|
||||||
|
|
||||||
cin >> a >> b >> k >> n >> m;
|
cin >> a >> b >> k >> n >> m;
|
||||||
|
|
||||||
cout << static_cast<long long>(C(k, n)) * binpow(a, n) % mod * binpow(b, m) % mod << endl;
|
cout << static_cast<long long>(C(k, n)) * binpow(a, n) % mod * binpow(b, m) % mod << endl;
|
||||||
|
41
Luogu/P2822/P2822.cpp
Normal file
41
Luogu/P2822/P2822.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 2005;
|
||||||
|
|
||||||
|
int t, k, n, m, c[N][N], f[N][N];
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
cin >> t >> k;
|
||||||
|
|
||||||
|
c[1][1] = 1;
|
||||||
|
for (int i = 1; i <= 2000; i++) {
|
||||||
|
c[i][0] = c[i][i] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 2; i <= 2000; i++) {
|
||||||
|
for (int j = 1; j < i; j++) {
|
||||||
|
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % k;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i <= 2000; i++) {
|
||||||
|
for (int j = 1; j <= i; j++) {
|
||||||
|
f[i][j] = f[i][j - 1] + f[i - 1][j] - f[i - 1][j - 1];
|
||||||
|
if (!c[i][j]) f[i][j]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
f[i][i + 1] = f[i][i];
|
||||||
|
}
|
||||||
|
|
||||||
|
while (t--) {
|
||||||
|
cin >> n >> m;
|
||||||
|
|
||||||
|
cout << f[n][std::min(n, m)] << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user