Cod sursa(job #2652489)

Utilizator stefan.popescuPopescu Stefan stefan.popescu Data 24 septembrie 2020 23:15:01
Problema Invers modular Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.23 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream in ("inversmodular.in");
ofstream out("inversmodular.out");

namespace Maths{
    typedef long long LL;
    using Maths::LL;

    const LL mod=998244353;

    LL *fact;
    inline void Initialize(int n){
        fact=new LL [n+1];
        fact[0]=1;
        for(int i=1; i<=n; i++){
            fact[i]=(fact[i-1]*i)%mod;
        }
    }
    void modularInverseUtil(LL & cmmdc, LL &x, LL &y, LL a, LL b){
        if(b==0){
            cmmdc=a;
            x=1; y=0;
            return;
        }
        modularInverseUtil(cmmdc, x, y, b, a%b);
        LL x0=x;
        x=y;
        y=x0-a/b*y;
    }
    inline LL expLog(LL x, LL put){
        LL prod=1;
        while(put){
            if(put&1)
                prod*=x, prod%=mod;
            put>>=1, x=(x*x)%mod;
        }
        return prod;
    }
    inline LL invMod(LL a, LL b=mod){
        LL x, y, cmdc;
        modularInverseUtil(cmdc, x, y, a, b);
        return x;
    }
    inline LL calcComb(int n, int k){
        return fact[n]*invMod(fact[n-k]*fact[k]%mod)%mod;
    }

};
int x, y;
int main()
{
    in>>x>>y;
    out<<Maths::invMod(x, y);
    return 0;
}