Cod sursa(job #1264348)
Utilizator | Data | 15 noiembrie 2014 18:59:25 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include<fstream>
#include<algorithm>
using namespace std;
int x,y,a,b;
void solve(int a,int b,int &x,int &y) {
int x0,y0;
if(!b) x=1,y=0;
else solve(b,a%b,x0,y0),x=y0,y=x0-(a/b)*x;
}
int main()
{
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
cin>>a>>b;
solve(a,b,x,y);
while(x<0) x+=b;
cout<<x<<'\n';
return 0;
}