Cod sursa(job #1127001)
Utilizator | Data | 27 februarie 2014 10:46:34 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
#define ll long long
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
ll A, N, inv, garbage, d;
ll euclidextins(ll A, ll B, ll &x, ll &y)
{
if (!B) { x=1; y=0; return A; }
ll x0, y0, d=euclidextins(B, A%B, x0, y0);
x=y0; y=x0-(A/B)*y0;
return d;
}
int main()
{
f>>A>>N;
d=euclidextins(A, N, inv, garbage);
while (inv<0) inv+=N;
g<<inv<<'\n';
return 0;
}