Cod sursa(job #2105416)
Utilizator | Data | 13 ianuarie 2018 10:40:06 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <fstream>
using namespace std;
ifstream fin ("inversmodular.in");
ofstream fout ("inversmodular.out");
void EuclidE(int a,int b,int &x,int &y,int &d)
{
if(b==0){x=1;y=0;d=a;}
else{int x0,y0;
EuclidE(b,a%b,x0,y0,d);
x=y0; y=x0-a/b*y0;
}
}int a,n,x,y,d;
int main(){
fin>>a>>n;
EuclidE(n,a,x,y,d);
while(y<1)y=y+n;
fout<<y;
return 0;
}