Cod sursa(job #3213614)
Utilizator | Data | 13 martie 2024 12:15:14 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int Put(int a, int b, int MOD)
{
int p = 1;
while(b)
{
if (b % 2)
p = 1LL * a * p % MOD;
b /= 2;
a = 1LL * a * a % MOD;
}
return p;
}
int main()
{
int a, b;
fin >> a >> b;
fout << Put(a, b - 2, b);
return 0;
}