Cod sursa(job #1046826)
Utilizator | Data | 3 decembrie 2013 16:47:12 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <cstdio>
using namespace std;
void euclid(long long a,long long b,long long &x,long long &y)
{
if(!b)
{
x = 1;
y = 0;
return;
}
long long x1,y1;
euclid(b,a%b,x1,y1);
x = y1;
y = x1 - y1*(a/b);
}
int main()
{
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
long long a,b,x,y;
scanf("%lld%lld",&a,&b);
euclid(a,b,x,y);
printf("%d",(x+b)%b);
return 0;
}