Cod sursa(job #2067177)
Utilizator | Data | 15 noiembrie 2017 23:22:55 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.34 kb |
#include <iostream>
#include <fstream>
using namespace std;
int n,a;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
int main()
{ in>>a>>n;
int y0=0,y1=1,r,c,y,aux;
aux=n;
while(a!=0)
{ r=n%a;
c=n/a;
n=a;
a=r;
y=y0-c*y1;
y0=y1;
y1=y;
}
while(y0<=0) y=y+aux;
out<<y0;
return 0;
}