Cod sursa(job #2175036)
Utilizator | Data | 16 martie 2018 14:52:16 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void gcd(int a,int b,long long &x,long long &y)
{
if(!b)
{
x=1;
y=0;
}
else
{
gcd(b,a%b,x,y);
int au=x;
x=y;
y=au-(a/b)*y;
}
}
int main()
{
long long x=0,y;
int n,p;
fin>>n>>p;
gcd(n,p,x,y);
if(x<0)
x=x+x%p;
fout<<x;
}