Cod sursa(job #1881599)
Utilizator | Data | 16 februarie 2017 16:45:55 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 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%n;
else g<<(0-x)%n;
return 0;
}