Cod sursa(job #993100)
Utilizator | Arnold Beiland BeilandArnold | Data | 3 septembrie 2013 11:44:09 |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
void euclid_extins(int *x, int *y, int a, int b){
if(b==0){
*x=1;
*y=0;
}
else{
int x0,y0,c=a/b;
euclid_extins(&x0,&y0,b,a%b);
*x=y0;
*y=x0-c*y0;
}
}
int main(){
std::ifstream fin("inversmodular.in");
std::ofstream fout("inversmodular.out");
int a,n;
fin>>a>>n;
int x,y;
euclid_extins(&x,&y,a,n);
while(x<0) x+=n;
fout<<x<<'\n';
}