Cod sursa(job #1398358)
| Utilizator | Data | 24 martie 2015 10:01:56 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
#include <fstream>
#include <cmath>
#define LL long long
using namespace std;
void cmmdc(LL &x,LL &y,int a,int b)
{
if(b==0)
{
x=1;
y=0;
}
else
{
cmmdc(x,y,b,a%b);
LL aux=x;
x=y;
y=aux - y * ( a / b );
}
}
int main()
{
int a,n;
LL inv=1,y;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
f>>a>>n;
cmmdc(inv,y,a,n);
if(inv<=0)
inv=n + inv%n;
g<<inv;
}
