Cod sursa(job #1817032)

Utilizator NicolaalexandraNicola Alexandra Mihaela Nicolaalexandra Data 27 noiembrie 2016 12:09:01
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.54 kb
#include <fstream>

using namespace std;
long long n,a,x,y;
ifstream fin ("inversmodular.in");
ofstream fout ("inversmodular.out");
void Invers_Modular (long long a,long long b,long long &x,long long &y){
    if (b==0){
        x = 1;
        y = 0;
    }
    else{
        long long xa,ya;
        Invers_Modular (b,a%b,xa,ya);
        x = ya;
        y = xa- (a/b)*ya;
    }


}
int main (){

    fin>>a>>n;
    Invers_Modular(a,n,x,y);
    if (x < 0)
        x = (x+ (((-x)/n +1)*n)   )%n;
    fout<<x;



    return 0;
}