Cod sursa(job #2848153)
| Utilizator | Data | 12 februarie 2022 10:37:36 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("inversmodular.in");
ofstream fout("inversmodular.out");
void euclid(long long a,long long b,long long &d,long long &x,long long &y)
{
if (b == 0) d=a,x=1,y=0;
else
{
long long x0,y0;
euclid(b,a%b,d,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
int main()
{
long long int a,n;
fin>>a>>n;
long long int d,x,y;
euclid(a,n,d,x,y);
while (x<1)
{
x+=n;
}
if (x>n-1)
x=-1;
fout<<x;
return 0;
}
