Cod sursa(job #1584891)
Utilizator | Data | 30 ianuarie 2016 16:26:57 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
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(long long &x,long long &y,int a,int b)
{
if(b==0)
{
x=1;
y=0;
}
else
{
long long x0,y0;
gcd(x0,y0,b,a%b);
x=y0;
y=x0-(a/b)*y0;
}
}
int main()
{
int n,m;
long long x=0,y;
fin>>n>>m;
gcd(x,y,n,m);
if(x<=0) x=m+x%m;
fout<<x;
}