Cod sursa(job #2126069)
Utilizator | Data | 9 februarie 2018 00:28:52 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
using namespace std;
void cmmdc(int a,int b,int &x,int &y)
{
if(!b)
{
x=1;
y=0;
return ;
}
int x0,y0;
cmmdc(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
int main()
{
int a,n,x,y;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
in>>a>>n;
cmmdc(a,n,x,y);
while(x<0)
x+=n;
out<<x;
return 0;
}