Cod sursa(job #2056314)
Utilizator | Data | 4 noiembrie 2017 10:53:29 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a,n,cop,x0,x1,r,c,x;
int main()
{
f>>a>>n;
cop=n;x0=1;x1=0;
while(n!=0)
{
r=a%n;
c=a/n;
a=n;
n=r;
x=x0-c*x1;
x0=x1;
x1=x;
}
if(x0<0) x0+=cop;
g<<x0<<'\n';
return 0;
}