Cod sursa(job #2404539)
| Utilizator | Data | 12 aprilie 2019 23:28:21 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
#define lld long long
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
lld n, p;
void gcd(lld &x, lld &y, int a, int b)
{
if (!b)
x = 1, y = 0;
else
{
gcd(x,y,b,a%b);
lld aux = x;
x = y;
y = aux - y*(a/b);
}
}
int main()
{
lld v1, v2;
fin>>n>>p;
gcd(v1, v2, n, p);
while (v1<0)v1+=p;
fout<<v1<<'\n';
return 0;
}
