Cod sursa(job #994739)
| Utilizator | Data | 6 septembrie 2013 10:42:35 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
using namespace std;
void euclid_extins(int *x, int *y, int a, int b)
{
if(b==0)
{
*x=1;
*y=0;
}
else
{
int x0,y0,c=a/b;
euclid_extins(&x0,&y0,b,a%b);
*x=y0;
*y=x0-c*y0;
}
}
int main()
{
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a,n;
fin>>a>>n;
int x,y;
euclid_extins(&x,&y,a,n);
while(x<0) x+=n;
fout<<x<<'\n';
}
