Cod sursa(job #1595430)
Utilizator | Data | 10 februarie 2016 11:50:19 | |
---|---|---|---|
Problema | Invers modular | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#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);
while (x<=0) x=x+N;
g<<x;
return 0;
}