Cod sursa(job #846195)
Utilizator | Data | 1 ianuarie 2013 18:01:35 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
#include<iostream>
#include<fstream>
using namespace std;
inline void gcd(int a, int b, int &x, int &y)
{
if(b==0) {
x=1;
y=0;
}
else {
int x0,y0;
gcd(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
int main ()
{
int a,n,x,y;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
f>>a>>n;
f.close();
gcd(a,n,x,y);
while(x<=0)
x=x+n;
if(x==n)
x=0;
g<<x;
g.close();
return 0;
}