Cod sursa(job #1173453)
| Utilizator | Data | 19 aprilie 2014 18:52:38 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
int aa,n;
void cmmdc(long long &x,long long &y,int a,int b)
{
if(b==0)
{
x=1;
y=0;
return;
}
else
{
cmmdc(x,y,b,a%b);
long long aux=x;
x=y;
y=aux-(a/b)*y;
}
}
int main()
{long long inv=0, ins;
in>>aa>>n;
cmmdc(inv,ins,aa,n);
if(inv<=0)
inv=inv%n+n;
out<<inv<<'\n';
return 0;
}
