E. Modular Stability

E. Modular Stabilitytime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

We define xmodyxmody as the remainder of division of xx by yy (%% operator in C++ or Java, mod operator in Pascal).Let’s call an array of positive integers [a1,a2,…,ak][a1,a2,…,ak] stable if for every permutation pp of integers from 11 to kk, and for every non-negative integer xx, the following condition is met:(((xmoda1)moda2)…modak−1)modak=(((xmodap1)modap2)…modapk−1)modapk(((xmoda1)moda2)…modak−1)modak=(((xmodap1)modap2)…modapk−1)modapkThat is, for each non-negative integer xx, the value of (((xmoda1)moda2)…modak−1)modak(((xmoda1)moda2)…modak−1)modak does not change if we reorder the elements of the array aa.For two given integers nn and kk, calculate the number of stable arrays [a1,a2,…,ak][a1,a2,…,ak] such that 1≤a1<a2<⋯<ak≤n1≤a1<a2<⋯<ak≤n.InputThe only line contains two integers nn and kk (1≤n,k≤5⋅1051≤n,k≤5⋅105).OutputPrint one integer — the number of stable arrays [a1,a2,…,ak][a1,a2,…,ak] such that 1≤a1<a2<⋯<ak≤n1≤a1<a2<⋯<ak≤n. Since the answer may be large, print it modulo 998244353998244353.
Examples
input
7 3
output
16
input
3 7
output
0
input
1337 42
output
95147305
input
1 1
output
1
input
500000 1
output
500000

#include<bits/stdc++.h>
#define ll long long
#define maxn 2010
#define frj(i,n,k) for(long long i=2;i<=n-k;i++)
#define mc(i,q,k) modC(i,q,k)
using namespace std;
ll n,k;
ll mod=998244353;
ll qpow(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 modC(ll n, ll m, ll mod)
{
    ll a = 1, b = 1;
    if(m > n - m)
        m = n - m;
    if(m < 0)
        return 0;
    while(m)
 {
        a = a * n % mod;
        b = b * m % mod;
        m--;
  n--;
    }
    return a * qpow(b, mod - 2) % mod;
}
int main()
{
    cin>>n>>k;
    if(k > n)
    {
        cout << "0" << endl;
    }
    else if (n == k)
    {
        cout << "1" << endl;
    }
    else if(k == 1)
    {
        cout <<n+k-k<< endl;
    }
    else
 {
        ll ans=mc(n - 1, k - 1, mod);
        frj(i,n,k)
  {
            ans=(ans + mc(n / i - 1, k - 1, mod))%mod;
        }
        cout<<ans<<endl;
 }
 return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值