Pagini recente » Cod sursa (job #1621303) | Cod sursa (job #1307648) | Cod sursa (job #3164736) | Rating Turcu George (Turcu_George_Alexandru_321CB) | Cod sursa (job #1595434)
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int A,N;
void c(long long &x,long long &y,int a, int b)
{ if(b==0) {x=1;y=0;}
else{ c(x,y,b,a%b);
long long aux=x;
x=y;
y=aux-y*a/b;
}
}
int main()
{ long long x=0,y;
f>>A>>N;
c(x,y,A,N);
if (x<=0) x=N+x%N;
g<<x;
return 0;
}