Cod sursa(job #2230275)
| Utilizator | Data | 9 august 2018 17:00:36 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("invermodular.out");
void euclid(int &x,int &y,int a,int b){
if(!b){
x = 1;
y = 0;
return ;
}
euclid(x,y,b,a%b);
int newx = y;
int newy = x - y * (a/b);
x = newx;
y = newy;
}
int main()
{
int x,y,a,b,d;
in>>a>>b;
euclid(x,y,a,b);
x %= b;
if(x < 0)
x += b;
cout<<x;
return 0;
}
