Cod sursa(job #229066)
Utilizator | Data | 9 decembrie 2008 07:18:35 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include<fstream>
using namespace std;
void cmmdc(int a, int b, long long &x, long long &y){
if(b){
cmmdc(b,a%b,x,y);
int aux=y;
y=x-(a/b)*y;
x=aux;
}
else
{
x=1;
y=0;
}
}
int main()
{
int n, a;
long long x, y;
ifstream f("inversmodular.in");
f>>a>>n;
f.close();
cmmdc(a,n,x,y);
ofstream g("inversmodular.out");
g<<x<<'\n';
g.close();
return 0;
}