有种方式叫一下子拔高思维难度,做一些比你思维量极限还要略高一筹的题目,可以迅速上升。虽然我还是想有一个比较陡的缓冲区。于是,1700~2400,直接5道题一个难度。这个博客一共20个题(1700到2000)。
这段时间做好每道题都毫无思路最后只能翻开答案的觉悟吧
#include
#include
#include
using namespace std;
typedef long long ll;
const ll mod = 998244353;
ll N, M;
ll mod_pow(ll x, ll n) {
ll res = 1;
while(n) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
ll mod_C(ll m, ll n) {
ll res = 1;
for (ll i = m; i >= m - n + 1; i--) res = res * i % mod;
for (ll i = 1; i <= n; i++) res = res * mod_pow(i, mod - 2) % mod;
return res;
}
int main() {
cin >> N >> M;
if (N == 2) cout << 0 << endl;
else {
ll ans = mod_C(M, N - 1) * (N - 2) % mod * mod_pow(2, N - 3) % mod;
cout << ans << endl;
}
return 0;
}
#include
#include
#include
using namespace std;
typedef long long ll;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
int T;
cin >> T;
while (T--) {
int a, b, k;
cin >> a >> b >> k;
if (a > b) swap(a, b);
int x = gcd(a, b);
a /= x, b /= x;
if ((ll)a * ((ll)k - 1) + 1 < b) cout << "REBEL" << endl;
else cout << "OBEY" << endl;
}
return 0;
}
#include
#include
#include
#include
using namespace std;
typedef long long ll;
ll N, B;
unordered_map<ll, ll> divisor(ll N) {
unordered_map<ll, ll> res;
for (ll i = 2; i <= N / i; i++) {
while (N % i == 0) {
res[i]++;
N /= i;
}
}
if (N != 1) res[N]++;
return res;
}
ll get(ll N, ll p) {
ll res = 0;
while (N) {
res += N / p;
N /= p;
}
return res;
}
int main() {
cin >> N >> B;
ll ans = 9e18;
unordered_map<ll, ll> m = divisor(B);
//cout << ans << endl;
for (auto p : m) {
ll a = p.first, b = p.second;
ll res = get(N, a);
ans = min(ans, res / b);
}
cout << ans << endl;
return 0;
}
/*
1000000000000000000 1000000000000
1000000000000000000 2
*/
#include
#include
using namespace std;
const int maxn = 100010;
typedef long long ll;
const ll mod = 1e9 + 7;
ll g[maxn] = { 2LL, 2LL };
int main() {
for (int i = 2; i <= 100000; i++) g[i] = (g[i - 1] + g[i - 2]) % mod;
ll N, M;
cin >> N >> M;
cout << ((g[N] + g[M] - 2 + mod) % mod) << endl;
return 0;
}
#include
#include
#include
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int maxn = 1000010;
ll fact[maxn] = { 1 }, infact[maxn] = { 1 };
ll mod_pow(ll x, ll n) {
ll res = 1;
while (n) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
int main() {
for (ll i = 1; i <= 1000000; i++) {
fact[i] = fact[i - 1] * i % mod;
infact[i] = infact[i - 1] * mod_pow(i, mod - 2) % mod;
}
ll N;
cin >> N;
ll ans = fact[N];
for (ll i = 1; i < N; i++) {
ans = (ans + fact[N] * infact[N - i] % mod * ((fact[N - i] - 1 + mod) % mod)) % mod;
}
cout << ans << endl;
return 0;
}
/*
1 1
2 2
3 9
4 56
5 395
6 3084
7 26621
8 253280
9 2642391
10 30052700
*/
#include
#include
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
ll phi(ll n) {
ll res = n;
for (ll i = 2; i <= n / i; i++) {
if (n % i == 0) {
res = res / i * (i - 1);
while (n % i == 0) n /= i;
}
}
if (n != 1) res = res / n * (n - 1);
return res;
}
int main() {
int T;
cin >> T;
while (T--) {
ll a, m;
cin >> a >> m;
ll d = gcd(a, m);
cout << phi(m / d) << endl;
}
return 0;
}
#include
#include
#include
using namespace std;
typedef long long ll;
ll N, M, P;
const int maxn = 1000010;
ll a[maxn], b[maxn];
int main() {
scanf("%lld%lld%lld", &N, &M, &P);
for (int i = 0; i < N; i++) scanf("%lld", &a[i]);
for (int j = 0; j < M; j++) scanf("%lld", &b[j]);
int id1, id2;
for (id1 = 0; id1 < N; id1++) {
if (a[id1] % P != 0) break;
}
for (id2 = 0; id2 < M; id2++) {
if (b[id2] % P != 0) break;
}
printf("%d\n", id1 + id2);
return 0;
}
#include
#include
using namespace std;
const int maxn = 300010, maxa = 15000010;
int st[maxa], prime[maxa], cnt;
void sieve(int N) {
for (int i = 2; i <= N; i++) {
if (!st[i]) st[i] = prime[cnt++] = i;
for (int j = 0; prime[j] <= N / i; j++) {
st[prime[j] * i] = prime[j];
if (i % prime[j] == 0) break;
}
}
}
int N, a[maxn];
int res[maxa];
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
scanf("%d", &N);
int d = 0;
sieve(maxa - 1);
for (int i = 1; i <= N; i++) {
scanf("%d", &a[i]);
//这里取了个巧。当 d == 0时,gcd(0, a) = a.
d = gcd(d, a[i]);
}
for (int i = 1; i <= N; i++) {
for (int j = a[i] / d; j > 1;) {
//找到 j 的最小质因数
int x = st[j];
// 更新答案
res[x]++;
//把j一直除以最小质因数,直到不能被 x 整除为止。
while (j % x == 0) {
j /= x;
}
}
}
int ans = 0;
for (int i = 0; i < cnt; i++) {
//仍然小心这个地方!不要把 i 当成 prime[i] !!!
int p = prime[i];
ans = max(ans, res[p]);
}
printf("%d\n", ans ? N - ans : -1);
return 0;
}
#include
#include
#include
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1000010;
ll fact[maxn], infact[maxn];
ll mod_pow(ll x, ll n) {
ll res = 1;
while (n) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
ll a, b, n;
bool mu(ll x) {
ll res = x * a + (n - x) * b;
while (res) {
ll d = res % 10;
if (d != a && d != b) return false;
res /= 10;
}
return true;
}
ll C(ll m, ll n) {
return fact[m] * infact[n] % mod * infact[m - n] % mod;
}
int main() {
cin >> a >> b >> n;
ll ans = 0;
fact[0] = infact[0] = 1;
for (ll i = 1; i <= n; i++) {
fact[i] = fact[i - 1] * i % mod;
infact[i] = infact[i - 1] * mod_pow(i, mod - 2) % mod;
}
for (ll i = 0; i <= n; i++) {
if (mu(i)) {
ans = (ans + C(n, i)) % mod;
}
}
cout << ans << endl;
return 0;
}
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int maxn = 300010;
const ll mod = 998244353;
typedef pair<int, bool> P;
vector<P> v;
ll N, K, fact[maxn] = { 1 }, infact[maxn] = { 1 };
ll mod_pow(ll x, ll n) {
ll res = 1;
while (n) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
ll C(ll m, ll n) {
if (n > m) return 0;
return fact[m] * infact[n] % mod * infact[m - n] % mod;
}
int main() {
scanf("%d%d", &N, &K);
for (ll i = 1; i <= N; i++) {
fact[i] = fact[i - 1] * i % mod;
infact[i] = infact[i - 1] * mod_pow(i, mod - 2) % mod;
}
for (int i = 0; i < N; i++) {
int l, r;
scanf("%d%d", &l, &r);
v.push_back(P(l, false));
v.push_back(P(r, true));
}
sort(v.begin(), v.end());
int cnt = 0;
ll ans = 0;
for (int i = 0; i < 2 * N; i++) {
if (v[i].second) cnt--;
else {
cnt++;
if (cnt < K) continue;
ans = (ans + C((ll)cnt - 1, K - 1)) % mod;
}
}
printf("%lld\n", ans);
return 0;
}
#include
#include
using namespace std;
typedef unsigned long long ll;
ll A, B, N;
ll sum1(ll x) {
if (x & 1) return (x + 1) / 2 * x;
else return x / 2 * (x + 1);
}
ll sum2(ll x) {
ll a[3] = { x, x + 1, 2 * x + 1 };
int id1 = 0, id2 = 0;
for (int i = 0; i < 3; i++) {
if (a[i] % 2 == 0) id1 = i;
if (a[i] % 3 == 0) id2 = i;
}
a[id1] /= 2, a[id2] /= 3;
return a[0] * a[1] * a[2];
}
ll sum3(ll x) {
if (x & 1) return ((x + 1) / 2) * ((x + 1) / 2) * x * x;
else return (x / 2) * (x / 2) * (x + 1) * (x + 1);
}
ll sumup(ll l, ll r, ll k) {
if (k == 0) {
return r - l + 1;
}
else if (k == 1) {
return sum1(r) - sum1(l - 1);
}
else if (k == 2) {
return sum2(r) - sum2(l - 1);
}
else if (k == 3) {
return sum3(r) - sum3(l - 1);
}
}
int main() {
cin >> A >> B >> N;
ll res1 = 0, res2 = 0;
for (ll l = 1, r; l <= N; l = r + 1) {
r = min(N / (N / l), N);
res1 += (N / l) * sumup(l, r, A);
res2 += (N / l) * sumup(l, r, B);
}
cout << (res1 ^ res2) << endl;
return 0;
}
#include
#include
using namespace std;
const int maxn = 200010;
typedef long long ll;
const ll mod = 998244353;
ll deg[maxn], fact[maxn] = { 1 };
int N;
int main() {
scanf("%d", &N);
for (ll i = 1; i <= N; i++) {
fact[i] = fact[i - 1] * i % mod;
}
for (int i = 1; i < N; i++) {
int a, b;
scanf("%d%d", &a, &b);
deg[a]++, deg[b]++;
}
ll ans = N;
for (int i = 1; i <= N; i++) {
ans = ans * fact[deg[i]] % mod;
}
printf("%lld\n", ans);
return 0;
}
#include
#include
using namespace std;
typedef long long ll;
ll n, l, v1, v2, k;
int main() {
cin >> n >> l >> v1 >> v2 >> k;
ll cnt = (n + k - 1) / k;
double x = 2.0 * v1 * l * (cnt - 1) / ((double)(2 * cnt - 1) * v1 + v2);
double ans = x / v1 + (l - x) / v2;
printf("%.18f\n", ans);
return 0;
}
#include
#include
using namespace std;
typedef long long ll;
ll a00, a01, a10, a11, a, b;
ll binary_find(ll x) {
ll lb = 1, ub = x + 3;
while (ub - lb > 1) {
ll mid = (lb + ub) / 2;
if (mid * (mid - 1) / 2 <= x) lb = mid;
else ub = mid;
}
if (lb * (lb - 1) / 2 != x) return -1;
return lb;
}
int main() {
scanf("%lld%lld%lld%lld", &a00, &a01, &a10, &a11);
if (a01 == 0 && a10 == 0) {
if (a00 == 0 && a11 == 0) a = 0, b = 0;
else if (a00 == 0) a = 0, b = binary_find(a11);
else if (a11 == 0) a = binary_find(a00), b = 0;
else{
printf("Impossible\n");
return 0;
}
if (a == -1 || b == -1) {
printf("Impossible\n");
return 0;
}
for (int i = 0; i < a; i++) printf("0");
for (int i = 0; i < b; i++) printf("1");
if (a == 0 && b == 0) printf("0");
printf("\n");
}
else {
a = binary_find(a00), b = binary_find(a11);
if (a == -1 || b == -1 || a * b != a01 + a10) {
printf("Impossible\n");
}
else {
ll x1 = (a * b - a10) / b, x2 = (a * b - a10) % b;
for (int i = 0; i < x1; i++) printf("0");
a -= x1;
for (int i = 0; i < b - x2; i++) printf("1");
b = x2;
if (x2 != 0 && a > 0) {
printf("0");
a--;
}
for (int i = 0; i < b; i++) printf("1");
for (int i = 0; i < a; i++) printf("0");
printf("\n");
}
}
return 0;
}
法一:
#include
#include
#include
using namespace std;
const int maxn = 100010;
int divisor_id[maxn];
int prime[maxn], cnt, st[maxn];
vector<int> divisor(int N) {
vector<int> res;
for (int i = 1; i <= N / i; i++) {
if (N % i == 0) {
res.push_back(i);
if (i != N / i) res.push_back(N / i);
}
}
return res;
}
int main() {
int N;
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
int x, y;
scanf("%d%d", &x, &y);
vector<int> v = divisor(x);
int ans = 0;
for (int u : v) {
if (divisor_id[u] < i - y) ans++;
divisor_id[u] = i;
}
printf("%d\n", ans);
}
return 0;
}
法二:
#include
#include
#include
using namespace std;
const int maxn = 100010;
int divisor_id[maxn];
int prime[maxn], cnt, st[maxn];
vector<int> divisor[maxn];
void divisor_sieve(int N) {
for (int i = 1; i <= N; i++) {
for (int j = i; j <= N; j += i) {
divisor[j].push_back(i);
}
}
}
int main() {
int N;
scanf("%d", &N);
divisor_sieve(100000);
for (int i = 1; i <= N; i++) {
int x, y;
scanf("%d%d", &x, &y);
vector<int>& v = divisor[x];
int ans = 0;
for (int u : v) {
if (divisor_id[u] < i - y) ans++;
divisor_id[u] = i;
}
printf("%d\n", ans);
}
return 0;
}
#include
#include
#include
using namespace std;
const int maxn = 10000010;
int prime[maxn], cnt, st[maxn];
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
void sieve(int N) {
for (int i = 2; i <= N; i++) {
if (!st[i]) prime[cnt++] = st[i] = i;
for (int j = 0; prime[j] <= N / i; j++) {
st[prime[j] * i] = prime[j];
if (i % prime[j] == 0) break;
}
}
}
vector<int> divisor(int N) {
vector<int> res;
for (int i = N; i > 1; ) {
//找到 j 的最小质因数
int x = st[i];
res.push_back(x);
//把j一直除以最小质因数,直到不能被 x 整除为止。
while (i % x == 0) {
i /= x;
}
}
return res;
}
int ans1[500010], ans2[500010];
int main() {
sieve(maxn - 1);
int N;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
int x;
scanf("%d", &x);
vector<int> v = divisor(x);
if (v.size() == 1) {
ans1[i] = -1, ans2[i] = -1;
continue;
}
ans1[i] = v[0], ans2[i] = 1;
for (int j = 1; j < v.size(); j++) {
ans2[i] *= v[j];
}
}
for (int i = 0; i < N; i++) printf("%d%c", ans1[i], i + 1 == N ? '\n' : ' ');
for (int i = 0; i < N; i++) printf("%d%c", ans2[i], i + 1 == N ? '\n' : ' ');
return 0;
}
#include
#include
#include
#include
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int a, b, c;
cin >> a >> b >> c;
int ans = 1e9;
int A0, B0, C0;
for (int A = 1; A <= 2 * a; A++) {
for (int B = A; B <= 2 * b; B += A) {
int C1 = c / B * B, C2 = (c / B + 1) * B;
int res = abs(a - A) + abs(b - B) + min(abs(c - C1), abs(c - C2));
if (ans > res) {
ans = res;
A0 = A, B0 = B;
if (abs(c - C1) < abs(c - C2)) C0 = C1;
else C0 = C2;
}
}
}
cout << ans << endl;
printf("%d %d %d\n", A0, B0, C0);
}
return 0;
}
#include
#include
#include
using namespace std;
const int maxn = 1010;
typedef pair<int, int> P;
struct res {
int cnt, px, py;
char op;
res(int c = 0, int x = 0, int y = 0, char o = 0) :cnt(c), px(x), py(y), op(o) {};
};
P m[maxn][maxn];
res f1[maxn][maxn], f2[maxn][maxn];
int N;
bool has_zero = false;
int x_zero, y_zero;
void dp() {
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (i == 1) {
f1[i][j] = { f1[i][j - 1].cnt + m[i][j].first, i, j - 1, 'R' };
}
else if (j == 1) {
f1[i][j] = { f1[i - 1][j].cnt + m[i][j].first, i - 1, j, 'D' };
}
else {
if (f1[i - 1][j].cnt < f1[i][j - 1].cnt) {
f1[i][j] = { f1[i - 1][j].cnt + m[i][j].first, i - 1, j, 'D' };
}
else {
f1[i][j] = { f1[i][j - 1].cnt + m[i][j].first, i, j - 1, 'R' };
}
}
}
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (i == 1) {
f2[i][j] = { f2[i][j - 1].cnt + m[i][j].second, i, j - 1, 'R' };
}
else if (j == 1) {
f2[i][j] = { f2[i - 1][j].cnt + m[i][j].second, i - 1, j, 'D' };
}
else {
if (f2[i - 1][j].cnt < f2[i][j - 1].cnt) {
f2[i][j] = { f2[i - 1][j].cnt + m[i][j].second, i - 1, j, 'D' };
}
else {
f2[i][j] = { f2[i][j - 1].cnt + m[i][j].second, i, j - 1, 'R' };
}
}
}
}
}
void Print(res f[][maxn]) {
printf("%d\n", f[N][N].cnt);
string path("");
for (res p = f[N][N];; p = f[p.px][p.py]) {
path += p.op;
if (p.px == 1 && p.py == 1) break;
}
reverse(path.begin(), path.end());
printf("%s", path.c_str());
}
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
int x;
scanf("%d", &x);
if (x == 0) {
has_zero = true, x_zero = i, y_zero = j;
x = 10;
}
while (x % 2 == 0) {
m[i][j].first++;
x /= 2;
}
while (x % 5 == 0) {
m[i][j].second++;
x /= 5;
}
}
}
dp();
//for (int i = 1; i <= N; i++) {
// for (int j = 1; j <= N; j++) {
// printf("%d ", f2[i][j].cnt);
// }
// printf("\n");
//}
if (has_zero) {
int ans = min(f1[N][N].cnt, f2[N][N].cnt);
ans = min(1, ans);
if (ans == 1) {
printf("1\n");
//别偷懒,画个图画个图,一画图就知道那里错了呀 :(
for (int j = 1; j < y_zero; j++) printf("R");
for (int i = 1; i < N; i++) printf("D");
for (int j = y_zero; j < N; j++) printf("R");
}
else if (ans == f1[N][N].cnt) Print(f1);
else Print(f2);
}
else {
if (f1[N][N].cnt < f2[N][N].cnt) Print(f1);
else Print(f2);
}
printf("\n");
return 0;
}
/*
4
2 5 2 5
5 2 0 5
2 5 2 2
5 5 2 5
*/
#include
#include
using namespace std;
int N, A, B;
const int maxn = 1000010;
double SumE[maxn], E[maxn];
int main() {
scanf("%d%d%d", &N, &A, &B);
double L = (double)B - A + 1;
if (A == 0) {
for (int i = 1; i <= N; i++) {
if (i <= B) {
E[i] = L / (L - 1) + 1.0 / (L - 1) * SumE[i - 1];
}
else {
E[i] = L / (L - 1) + 1.0 / (L - 1) * (SumE[i - 1] - SumE[i - B - 1]);
}
SumE[i] = E[i] + SumE[i - 1];
}
}
else {
for (int i = 1; i <= N; i++) {
if (i <= B) {
E[i] = 1 + 1.0 / L * SumE[max(i - A, 0)];
}
else {
E[i] = 1 + 1.0 / L * (SumE[i - A] - SumE[i - B - 1]);
}
SumE[i] = SumE[i - 1] + E[i];
}
}
printf("%.10f\n", E[N]);
return 0;
}
#include
#include
using namespace std;
typedef long long ll;
const int maxn = 3000010;
ll f[maxn], g[maxn], A, B, C, D;
int main() {
scanf("%lld%lld%lld%lld", &A, &B, &C, &D);
//枚举第一个数字
for (int i = 0; i <= A; i++) {
f[i]++;
f[i + B + 1]--;
}
for (int i = 1; i <= A + B; i++) f[i] += f[i - 1];
//同样也是枚举第一个数字
for (int i = 0; i <= A + B; i++) {
g[i] += f[i];
g[i + C + 1] -= f[i];
}
for (int i = 1; i <= A + B + C; i++) {
g[i] += g[i - 1];
}
ll ans = 0;
for (int i = 0; i <= D; i++) ans += g[i];
printf("%lld\n", ans);
return 0;
}