Cod sursa(job #933095)
| Utilizator | Data | 29 martie 2013 16:48:18 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
#include <iostream>
using namespace std;
ifstream f("inversmodular.in"); ofstream g("inversmodular.out");
void gcd (int a, int b, int &d, int &x, int &y){
if (b==0){
d=a;
x=1; y=0;
}
else {
int x0, y0;
gcd (b, a%b, d, x0, y0);
x = y0;
y = x0 - (a/b)*y0;
}
}
int main(){
int d, n, x, t1, t2;
f>>d>>n;
gcd (d, n, t1, x, t2);
while (x<0) x+=n;
x%=n;
g<<x;
}
