Cod sursa(job #1460626)
| Utilizator | Data | 13 iulie 2015 13:20:41 | |
|---|---|---|---|
| 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 fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A,N;
ll inv,ins;
void invers (int a, int b, ll &x, ll &y)
{
if(!b)
x=1,y=0;
else
{
invers(b,a%b,x,y);
ll aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main()
{
fin>>A>>N;
invers(A,N,inv,ins);
if(inv<=0)
inv=inv%N+N;
fout<<inv;
return 0;
}
