Cod sursa(job #952449)
Utilizator | Data | 23 mai 2013 15:23:57 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include<fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int n,x,y,a;
void euc(int &x,int &y,int a,int b)
{
if(!b) {x=1; y=0;}
else
{
euc(x,y,b,a%b);
int x0,y0;
x0=x;y0=y;
x=y;
y=x0-a/b*y0;
}
}
int main()
{
f>>a>>n;
x=1;
euc(x,y,a,n);
while(x<=0)
x+=n;
g<<x;
return 0;
}