Cod sursa(job #2270517)
Utilizator | Data | 27 octombrie 2018 11:22:51 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
using namespace std;
void fct(int x,int y,int &k,int &l)
{
int kp,lp;
if(y==0)
{
l=0;
k=1;
return;
}
fct(y,x%y,kp,lp);
k=lp;
l=kp-lp*(x/y);
}
int main()
{
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a,n,k,l;
fin>>a>>n;
fct(a,n,k,l);
while(l<0)
l+=a;
fout<<l;
return 0;
}