Cod sursa(job #2417633)

Utilizator SqueekDanielTodasca Daniel SqueekDaniel Data 30 aprilie 2019 17:01:34
Problema Infasuratoare convexa Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.69 kb
#include <bits/stdc++.h>

#define llg long long

namespace maths {
    void euclid(llg A, llg B, llg &X, llg &Y) {
        if (B == 0) {
            Y = 0, X = 1;
            return;
        }   euclid(B, A%B, X, Y);
        llg aux = Y; Y = X - (A/B)*Y; X = aux;
    }

    llg invmod(llg A, llg MOD) {
        llg temp, inv;
        euclid(A, MOD, inv, temp);
        return (inv+MOD)%MOD;
    }
}

llg A, N;

std::ifstream input ("inversmodular.in");
std::ofstream output("inversmodular.out");

void readInput() {
    input >> A >> N;
}

void solveInput() {
    output << maths::invmod(A, N);
}

int main()
{
    readInput();
    solveInput();

    return 0;
}