Pagini recente » Cod sursa (job #1415925) | Diferente pentru problema/indep intre reviziile 3 si 4 | Cod sursa (job #1220491) | Cod sursa (job #1696241) | Cod sursa (job #3298138)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void invmod(int &x,int &y,int a, int b){
if(!b)
x=1,y=0;
else{
invmod(x,y,b,a%b);
int aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main(){
int a,b;
fin>>a>>b;
int x,y;
invmod(x,y,a,b);
while(x<0) {
x+=b;
}
fout<<x;
return 0;
}