Cod sursa(job #2741467)

Utilizator smoc_georgemarianSmoc George-Marian smoc_georgemarian Data 16 aprilie 2021 00:19:56
Problema Invers modular Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.94 kb
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define NMAX 1009
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
ll fact[NMAX];
ll i;
ll powmod(ll a, ll b, ll p) {
    a %= p;
    if (a == 0) return 0;
    ll product = 1;
    while (b > 0) {
        if (b & 1) {    // you can also use b % 2 == 1
            product *= a;
            product %= p;
            --b;
        }
        a *= a;
        a %= p;
        b /= 2;    // you can also use b >> 1
    }
    return product;
}
ll inv(ll a, ll p) {
    return powmod(a, p - 2, p);
}
ll nCk(ll n, ll k, ll p) {

    return ((fact[n] * inv(fact[k], p) % p) * inv(fact[n - k], p)) % p;
}
void pre(ll p)
{
    ll i;
    fact[0] = 1LL;
    for (i = 1; i < NMAX; i++)
        fact[i] = (fact[i - 1] * i) % p;
    
}
int main()
{
    ll a, n;
    fin >> a >> n;
    fout << inv(a, n);
	return 0;
}