Cod sursa(job #2371677)

Utilizator 0738076326Simon Wil 0738076326 Data 6 martie 2019 18:58:28
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.46 kb
#include <fstream>

using namespace std;

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

void invrs(long long int &x, long long int &y, int a, int b){
    if(!b)
        x=1,y=0;
    else{
        invrs(x,y,b,a%b);
        swap(x,y);
        y=y-x*(a/b);
    }

}

int main(){
    long long int inv=0,ins;
    int a,b;
    f>>a>>b;
    invrs(inv,ins,a,b);

    if(inv<=0)
        inv = b+inv%b;

    g<<inv;

return 0;
}