Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
2,689 views
in Online Assessments by Expert (111,270 points) | 2,689 views

2 Answers

0 like 0 dislike

Here is the question ::::: 

by Expert (111,270 points)
0 like 0 dislike

C++ code : 



#include <bits/stdc++.h>

using namespace std;
typedef long long int ll ; 
ll mod = 998244853 ; 

long long int me(long long int x,long long int n,long long int M)

{

 long long int result=1;

    while(n>0)

    {

        if(n%2==1)

            result=(__int128)(result*x)%M;

        x=(x*x)%M;

        n=n/2;

    }

    return result;

}

//6)calculates : (1/(a^b))%M;

ll modInverse(ll A,ll B,ll M)

{

    ll k=B*(M-2);

    return me(A,k,M);

}

//7)Calculating factorial and inverse factorial : 

vector<ll> fact;

vector<ll> invfact;

void computefactorial(ll n,ll p)

{

    fact.resize(n+1); 

    invfact.resize(n+1);

    fact[0]=1;

    for(ll i=1;i<=n;i++)

    {

        fact[i]=i*fact[i-1];

        fact[i]%=p;

    }

    invfact[n]=modInverse(fact[n],1,p);

    for(ll i=n-1;i>=0;i--){

        invfact[i]=(i+1)*invfact[i+1];

        invfact[i]%=p;

    }

}

ll nCr(ll n,ll r,ll p) 

{ 

return (  ((fact[n]*invfact[r])%p) * (invfact[n-r]%p) ) % p; 

}
int main() {
    
    computefactorial(200000,mod);
    ll n,m ; 
    cin>>n>>m ;
    if(m>=n){
        ll v2 = m + 1 - n ;
        ll v5 = m + 1 ;
        
        ll v8 = nCr(n+m,m,mod);
        ll ans = (v2*v8)%mod ; 
        ll gp = modInverse(v5,1,mod);
        cout<<(ans*gp)%mod ; 
        
    }
    else{
        cout<<"-1";
    }
}
by Expert (111,270 points)