传送门Denso Create Programming Contest 2022 Winter(AtCoder Beginner Contest 280)
∗ * ∗D - Factorial and Multiple
Tutorial
分解 K K K 的因数, K = p 1 a 1 p 2 a 2 ⋯ p m a m K=p_1^{a_1}p_2^{a_2}\cdots p_m^{a_m} K=p1a1p2a2⋯pmam ,对于每一个因数 p i p_i pi ,我们要找出最小的 N i N_i Ni 使得 1 ∽ N i 1\backsim N_i 1∽Ni 中包含 a i a_i ai 个因数 p i p_i pi ,找出最大的这样的 N i N_i Ni 即可。
Solution
#include <bits/stdc++.h>
#define int long long
#define vi vector<int>
#define pii pair<int, int>
#define inf 0x3f3f3f3f
const int N = 500 + 7;
using namespace std;
void solve() {
int k, ans = 1, a, n, x;
cin >> k;
for (int p = 2; p * p <= k; p++) {
a = 0, n = 0;
while (k % p == 0) k /= p, a++;
while (a > 0) {
n += p;
x = n;
while (x % p == 0) x /= p, a--;
}
ans = max(ans, n);
}
ans = max(k, ans);
cout << ans;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T = 1;
while (T--) solve();
}
E - Critical Hit
Tutorial
dp
设
f
[
i
]
f[i]
f[i] 表示造成
i
i
i 点伤害的期望攻击数,不难得知
f
[
i
]
f[i]
f[i] 由前一次攻击不暴击和前前一次攻击暴击转移而来,故有:
f
[
i
]
=
f
[
i
−
2
]
×
p
100
+
f
[
i
−
2
]
×
(
1
−
p
100
)
+
1
f[i]=f[i-2]\times \frac{p}{100}+f[i-2]\times (1-\frac{p}{100})+1
f[i]=f[i−2]×100p+f[i−2]×(1−100p)+1
注意分数取模即可
Solution
#include <bits/stdc++.h>
#define int long long
#define vi vector<int>
#define pii pair<int, int>
#define inf 0x3f3f3f3f
const int N = 2e5 + 7, mod = 998244353;
using namespace std;
int f[N];
int qpow(int x, int y) {
int res = 1;
while (y) {
if (y & 1) res = (res * x) % mod;
x = (x * x) % mod;
y >>= 1;
}
return res;
}
void solve() {
int n, p;
cin >> n >> p;
int x = qpow(100, mod - 2);
f[0] = 0;
f[1] = 1;
for (int i = 2; i <= n; i++) f[i] = (f[i - 2] * p % mod * x % mod + f[i - 1] * (100 - p) % mod * x % mod + 1) % mod;
cout << f[n];
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T = 1;
while (T--) solve();
}