Cod sursa(job #2164567)
Utilizator | Data | 13 martie 2018 08:14:57 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a, b, z=1, x, y, inv, c, r;
int main()
{
f >> a >> b ;
inv = b;
while( a )
{
r = b%a;
c = b/a;
b = a;
a = r;
x = y-c*z;
y = z;
z = x;
}
while( y < 0 )
y += inv;
g << y <<"\n";
return 0;
}