1359E - Modular Stability - CodeForces Solution


combinatorics math number theory *2000

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 5e5 + 55, LG = 22, mod = 998244353, base1 = 1001491, base2 = 1000721;
ll fac[N];

ll mul(ll x, ll y){return (x%mod * y%mod)%mod;}
ll add(ll x, ll y){return (x%mod + y%mod)%mod;}

void init(){
    fac[0] = 1;
    for(ll i=1;i<N;i++)    fac[i] = mul(fac[i-1], i);
}

ll fp(int b, int p){
    if(p==0)    return 1;
    ll ans = fp(1LL * b * b % mod, p/2);
    if(p%2) return 1LL * ans * b % mod;
    return ans;
}

ll ncr(int nn, int r){
    if(r>nn || r<0)    return 0LL;
    return  1LL * fac[nn] * fp(1LL * fac[r] * fac[nn-r] % mod, mod - 2)%mod;
}


void test_case(){
    init();
    ll n,k;     cin>>n>>k;
    ll ans = 0;
    if(k == 1){
        cout<<n;
        return;
    }
    for(int i=1;i<=n;i++){
        ans = add(ans, ncr(n/i - 1, k - 1));
    }
    cout<<ans;
}

int main(){
    FIO
//    freopen("important.in","rt",stdin);
//    freopen("output.txt","wt",stdout);
    int tc = 1;
//    cin>>tc;
    for(int i=1;i<=tc;i++){
//        cout<<"Case #"<<i<<": ";
        test_case();
    }
}


Comments

Submit
0 Comments
More Questions

1650C - Weight of the System of Nested Segments
1097A - Gennady and a Card Game
248A - Cupboards
1641A - Great Sequence
1537A - Arithmetic Array
1370A - Maximum GCD
149A - Business trip
34A - Reconnaissance 2
59A - Word
462B - Appleman and Card Game
1560C - Infinity Table
1605C - Dominant Character
1399A - Remove Smallest
208A - Dubstep
1581A - CQXYM Count Permutations
337A - Puzzles
495A - Digital Counter
796A - Buying A House
67A - Partial Teacher
116A - Tram
1472B - Fair Division
1281C - Cut and Paste
141A - Amusing Joke
112A - Petya and Strings
677A - Vanya and Fence
1621A - Stable Arrangement of Rooks
472A - Design Tutorial Learn from Math
1368A - C+=
450A - Jzzhu and Children
546A - Soldier and Bananas