Cod sursa(job #2855595)
Utilizator | Data | 22 februarie 2022 17:28:27 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
using namespace std;
ifstream fin ("inversmodular.in");
ofstream fout("inversmodular.out");
int Pow(int x, int y, int mod)
{
if (y==0) return 1;
if (y==1) return x%mod;
int p=Pow(x, y/2, mod);
if (y%2==0) return (1LL*p*p)%mod;
else return ((1LL*p*p)%mod*x)%mod;
}
int main()
{
int a, n;
fin>>a>>n;
fout<<Pow(a, n-2, n);
return 0;
}