Cod sursa(job #2038090)
| Utilizator | Data | 13 octombrie 2017 10:34:37 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("inversmodular.in");
ofstream g ("inversmodular.out");
void euclid(int a,int b,int &x,int &y)
{
if(b == 0)
{
x = 1; y = 0;
return;
}
int x0, y0;
euclid(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b)*y0;
}
int main()
{
int a,mod,x , y;
f >> a >> mod;
euclid(a , mod, x , y);
if(x < 0)
x = x % mod + mod;
g << x;
return 0;
}
