Cod sursa(job #333709)
Utilizator | Gutu Pavel levap1506 | Data | 23 iulie 2009 16:24:36 |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
#define SL long long
using namespace std;
void cmmdc(SL &x,SL &y, SL a, SL b)
{
if (b==0)
{
x=1;
y=0;
return;
}
SL x0,y0;
cmmdc(x0,y0,b,a%b);
x=y0;
y=x0-(a/b)*y0;
}
ifstream in;
ofstream out;
SL N,i,j,k,M,X,Y;
int main() {
in.open("inversmodular.in");
out.open("inversmodular.out");
in >> N >> M;
cmmdc(X, Y,N,M);
while (X<=0)
X+=N;
out << X;
out.close();
return 0;
}