Cod sursa(job #1386190)
Utilizator | Data | 12 martie 2015 19:49:14 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <iostream>
#include <fstream>
using namespace std;
long long x,y,a,b;
void gcd(int a, int b)
{
if(b==0)
x=1,y=0;
else
{
gcd(b,a%b);
long long aux=x;
x=y;
y=aux- y*(a/b);
}
}
int main()
{
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
in >> a >> b;
gcd(a,b);
if(x<0)
x=b+x%b;
out << x;
return 0;
}