Cod sursa(job #1371208)
| Utilizator | Data | 3 martie 2015 19:57:27 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
using namespace std;
void euclid(int a,int b,int& x,int& y){
if(b == 0){
x = 1;
y = 0;
return;
}
else{
int x0,y0;
euclid(b,a%b,x0,y0);
x = y0;
y = x0 - (a/b) * y0;
return;
}
}
int main()
{
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A,B;
fin >> A >> B;
int x,y;
euclid(A,B,x,y);
while(x < 0) x += B;
fout << x;
}
