Cod sursa(job #1536137)

Utilizator robx12lnLinca Robert robx12ln Data 25 noiembrie 2015 19:25:22
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.51 kb
#include<fstream>
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
int a,n,invsmod,k;
void euclid( int a, int b, int &x, int &y ){
    if( b == 0 ){
        x = 1;
        y = 0;
    }else{
        int x1 = 0,y1 = 0;
        euclid( b, a%b, x1, y1 );
        x = y1;
        y = x1 - a/b * y1;
    }
}
int main(){
    cin >> a >> n;
    euclid(a,n,invsmod,k);
    while( invsmod <= 0){
        invsmod += n;
    }
    cout << invsmod;
    return 0;
}