Pagini recente » Cod sursa (job #2900624) | Cod sursa (job #59168) | Cod sursa (job #1216107) | Cod sursa (job #2799881) | Cod sursa (job #993100)
Cod sursa(job #993100)
#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';
}