Cod sursa(job #1135232)
Utilizator | Data | 7 martie 2014 15:18:21 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <fstream>
#define L long long
using namespace std;
void gcd(L a,L b,L &x,L &y)
{
if(!b)
{
x=1;
y=0;
return;
}
L x0,y0;
gcd(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int main()
{
L a,b,x,y;
fin>>a>>b;
gcd(a,b,x,y);
if(x<0)
x=b+x%b;
fout<<x<<"\n";
return 0;
}