Cod sursa(job #1436273)
| Utilizator | Data | 15 mai 2015 17:21:32 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <bits/stdc++.h>
#define SL signed long
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
SL a,n;
void euclid(SL a ,SL b ,SL &x ,SL &y )
{
if (b == 0)
{
x = 1;
y = 0;
}
else
{
SL X,Y;
euclid(b ,a%b ,X,Y );
x = Y;
y = X-(a / b) * Y;
}
}
int main()
{
fin >> a >> n;
SL x,y;
euclid(a ,n ,x ,y );
if (x <= 0)
x = n + x%n;
fout << x;
return 0;
}
