Cod sursa(job #2174679)
| Utilizator | Data | 16 martie 2018 12:58:51 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <fstream>
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
int a, mod, rest[1005], x[1005], pas, cat;
int main()
{
cin >> a >> mod;
rest[1] = a;
rest[2] = mod;
x[1] = 1;
x[2] = 0;
pas = 3;
while(true)
{
cat = rest[pas-2]/rest[pas-1];
rest[pas] = rest[pas-2]%rest[pas-1];
x[pas] = x[pas-2]-x[pas-1]*cat;
if(rest[pas] == 0)
break;
pas++;
}
cout << x[pas-1];
}
