Pagini recente » Cod sursa (job #2073877) | Cod sursa (job #1507597) | Cod sursa (job #3166427) | Cod sursa (job #1848161) | Cod sursa (job #662946)
Cod sursa(job #662946)
#include<fstream>
#include<algorithm>
#include<math>
using namespace std;
long a,b,d,x,y,z,n,i;
void aeuclid(long a,long b,long z,long &x,long &y)
{
long x0,y0;
if (b==0){
z=a;
x=1;
y=0;
}
else {
aeuclid(b,a%b,z,x0,y0);
x=y0;
y = x0 - (a / b) * y0;
}
}
int main(){
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
f>>a>>n;
aeuclid(a,n,1,x,y);
while (x<0)
x=x+n;
g<<x;
return 0;
}