Cod sursa(job #1881598)
Utilizator | Data | 16 februarie 2017 16:44:46 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <fstream>
using namespace std;
#define ll long long
ll a,n,x,y;
void E(ll a,ll b,ll &x,ll &y)
{
if(!b)
{
x=1;
y=0;
}
else
{
ll x0,y0;
E(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
int main()
{
ifstream f("inversmodular.in");
f>>a>>n;
E(a,n,x,y);
ofstream g("inversmodular.out");
if(x>0)g<<x;
else g<<(0-x);
return 0;
}