Cod sursa(job #2532236)
| Utilizator | Data | 27 ianuarie 2020 16:35:48 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a,n;
void Read()
{
f>>a>>n;
f.close();
}
void gcd(ll &x,ll &y,int a,int b)
{
if(!b)
{
x = 1;
y = 0;
}
else
{
gcd(x, y, b,a % b);
ll aux = x;
x = y;
y = aux - y * (a / b);
}
}
int main()
{
ll inv = 0, ins;
Read();
gcd(inv, ins, a, n);
while(inv <= 0)
inv = n + inv % n;
g<<inv;
g.close();
return 0;
}
