Cod sursa(job #2711074)
Utilizator | Data | 23 februarie 2021 17:25:25 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
const int N = 100010;
int a,n,putere(int,int);
int main()
{
f>>a>>n;
g<<putere(a,n-2);
return 0;
}
int putere(int b,int e)
{
if(e==0)
return 1;
int r=putere(b,e/2);
r=1LL*r*r%n;
if(e%2==1)
r=1LL*r*b%n;
return r;
}