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;
}