E:Modular Stability(组合数)
生活随笔
收集整理的這篇文章主要介紹了
E:Modular Stability(组合数)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Modular Stability
思路
(((xmoda1)moda2)……modak?1)modak=(((xmodp1)modp2)……modpk?1)modpk(((x \mod a_1) \mod a_2) …… \mod a_{k - 1}) \mod a_{k} = (((x \mod p_1) \mod p_2) …… \mod p_{k - 1}) \mod p_{k}(((xmoda1?)moda2?)……modak?1?)modak?=(((xmodp1?)modp2?)……modpk?1?)modpk?,其中ppp數組是aaa數組的任意的排列。
這里的最小的aia_iai?一定是決定最后答案的,所以我們后面的ai+……a_{i + ……}ai+……?一定是最小aia_iai?的倍數,我們假定最小的數是a1a_1a1?,我們只需要去枚舉最小的數,然后求得剩下的數中,可以選出k?1k - 1k?1個滿足要求的數有多少個即C(n/a1?1,k?1)C(n / a_1 - 1, k - 1)C(n/a1??1,k?1),這里就正好用到我前幾天寫的板子了。
代碼
#include <bits/stdc++.h> #define mp make_pair #define pb push_backusing namespace std;typedef pair<int, int> pii; typedef long long ll; typedef unsigned long long ull;const double eps = 1e-7; const double pi = acos(-1.0); const int inf = 0x3f3f3f3f;inline ll read() {ll f = 1, x = 0;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9') {x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return f * x; }const int mod = 998244353; const int N = 5e5 + 10;ll fac[N], inv[N];ll qpow(ll a, int n) {ll ans = 1;while(n) {if(n & 1) ans = (ans * a) % mod;a = (a * a) % mod;n >>= 1;}return ans; }ll C(int n, int m) {if(n < 0 || m < 0 || m > n) return 0;if(m == 0 || m == n) return 1;return ((fac[n] * inv[m]) % mod * inv[n - m]) % mod; }void init() {fac[0] = 1;for(int i = 1; i < N; i++)fac[i] = (fac[i - 1] * i) % mod;inv[N - 1] = qpow(fac[N - 1], mod - 2);for(int i = N - 2; i >= 0; i--)inv[i] = (inv[i + 1] * (i + 1)) % mod; }int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);init();int n = read(), k = read();ll ans = 0;for(int i = 1; i <= n; i++) {ans += C(n / i - 1, k - 1);ans %= mod;}printf("%lld\n", ans);return 0; }總結
以上是生活随笔為你收集整理的E:Modular Stability(组合数)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Educational Codeforc
- 下一篇: 减肥茶配方有哪些