Mai intai trebuie sa te autentifici.
Cod sursa(job #1401841)
Utilizator | Data | 26 martie 2015 10:12:31 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
int A,N;
long long inv=0,ins;
void gcd(long long &x, long long &y, int a, int b)
{
if(!b)
{
x=1;
y=0;
}
else
{
gcd(x,y,b,a%b);
long long aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main()
{
cin>>A>>N;
gcd(inv,ins,A,N);
if(inv<=0)
inv=N+inv%N;
cout<<inv;
return 0;
}