Cod sursa(job #2110514)
| Utilizator | Data | 20 ianuarie 2018 19:21:07 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long a,n,x,y,d;
void Euclid_extins(long long a, long long b, long long &x, long long &y, long long &d)
{
if(b==0){d=a;x=1;y=0;}
else
{
long long x0,y0;
Euclid_extins(b,a%b,x0,y0,d);
x=y0;
y=x0-a/b*y0;
}
}
int main()
{
fin>>a>>n;
Euclid_extins(n,a,x,y,d);
while(y<1) y+=n;
fout<<y;
return 0;
}
