Cod sursa(job #2693809)

Utilizator CiboAndreiAndrei Cibo CiboAndrei Data 7 ianuarie 2021 09:23:18
Problema Invers modular Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.61 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
//#define f cin
//#define g cout

const int dim = 402;
const int mod = 1e9 + 7;

void turbo(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

long long x, m;

long long expo(int x, int m){
    long long ans = 1, md = m;
    m -= 2;

    while(m){
        if(m % 2 == 1)
            ans *= x;
        x *= x;
        m /= 2;

        ans %= md;
        x %= md;
    }

    return ans % md;
}

int main()
{
    turbo();

    f >> x >> m;

    g << expo(x, m);

    return 0;
}