Cod sursa(job #1110742)
Utilizator | Data | 18 februarie 2014 12:53:59 | |
---|---|---|---|
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, invers, y;
ll gcd_extins(ll a, ll b, ll &x, ll &y)
{
if (!b) { x=1; y=0; return a; }
ll x0, y0, d=gcd_extins(b, a%b, x0, y0);
x=y0; y=x0-(a/b)*y0;
return d;
}
int main()
{
f>>A>>N;
gcd_extins(A, N, invers, y);
while (invers<0)
invers+=N; g<<invers<<'\n';
return 0;
}