Cod sursa(job #1892786)
| Utilizator | Data | 25 februarie 2017 11:51:30 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
using namespace std;
long long a, n, d, x, y;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
void Euclid(long long a, long long b, long long &x, long long &y)
{
if(b==0)
{
x=1;
y=0;
return;
}
Euclid(b, a%b, x, y);
long long z=x;
x=y;
y=z-y*(a/b);
}
int main()
{
f>>a>>n;
Euclid(a, n, x, y);
if (x <= 0)
x=n+x%n;
g<<x;
return 0;
}
