Cod sursa(job #1072755)
| Utilizator | Data | 4 ianuarie 2014 20:27:00 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void cmmdc(int a, int b, int &x, int &y, int &rez)
{
if(!b)
{
rez=a;
x=1;
y=0;
}
else
{
int yy,xx;
cmmdc(b, a%b, xx, yy, rez);
x=yy;
y=(rez-a*x)/b;
}
}
int main()
{
int a, n, rez, x=0, y=0;
fin>>a>>n;
cmmdc(a, n, x, y, rez);
while(x<0)
x+=n;
while(x>n)
x-=n;
fout<<x<<"\n";
}
