Cod sursa(job #1171823)
Utilizator | Data | 16 aprilie 2014 13:46:19 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <fstream>
#define ll long long
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
ll m,n,inv,ins;
void fct(ll &x, ll &y, int a, int b)
{
if (!b)
x = 1, y = 0;
else
{
fct(x, y, b, a % b);
ll aux = x;
x = y;
y = aux - y * (a / b);
}
}
int main()
{
f>>m>>n;
fct(inv,ins,m,n);
if (inv <= 0)
inv=n+inv%n;
g<<inv;
f.close();
g.close();
}