E. Modular Stability——(Educational Codeforces Round 88 (Rated for Div. 2))

E. Modular Stability

链接

题目大意

给出\(n,k\),求出排列\(p\)的种数,其必须满足对于任意的\(x\)

\[(((x\ mod\ a_1)\ mod\ a_2) \cdots\ mod\ a_{k-1})\ mod\ a_k = (((x\ mod\ a_{p_1})\ mod\ a_{p_2}) \cdots mod\ a_{p_{k-1}})\ mod\ a_k \]

并且满足\(1 \leq a_1 < a_2 < \cdots < a_k \leq n\)

解题思路

首先如果要使得任意的\(x\)都满足上式,显而易见两边最后的结果都小于\(a_1\),所以必要保证在对其他数取模的时候结果与\(a_1\)取模答案一致,所以只有当所有数是\(a_1\)的倍数的时候在可以满足。
故直接枚举\(a_1\),使用组合数计算答案(\(\sum_{n / i - 1}^{k -1}\),这里需要保证一定要有一个i,所以这样计算)即可。

Code

#include <bits/stdc++.h>
#define ll long long
#define qc ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define pb push_back
#define V vector
using namespace std;
const int N = 5e5 + 7;
const ll mod = 998244353;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    return x*f;
}
ll f[N];
int n,k;
ll ksm(ll x,ll y)
{
    ll p = 1;
    while(y)
    {
        if(y & 1)p = p * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return p;
}
ll C(int x, int y)
{
    if(x < y)
        return 0ll;
    return (f[x] * ksm(f[y], mod - 2) % mod) * ksm(f[x - y], mod - 2) % mod;
}
void solve(){
    scanf("%d%d",&n,&k);
    f[0] = 1;
    for(int i = 1; i <= n; i++)
        f[i] = f[i - 1] * i % mod;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ans = (ans + C(n / i - 1, k - 1)) % mod;
    }
    printf("%lld\n",ans);
}

int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    int T = 1;
    // scanf("%d",&T);
    while(T--){
        solve();
    }
    return 0;
}
posted @ 2021-10-23 11:11  !^^!  阅读(34)  评论(0编辑  收藏  举报