Cod sursa(job #3147927)
| Utilizator | Data | 28 august 2023 10:28:07 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 60 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int64_t a,n,e;
int64_t produs(int64_t x,int64_t y)
{
x=x*y%n;
return x;
}
int64_t putere(int64_t b,int64_t e)
{
if(e==0LL)
return 1LL;
int64_t r=putere(b,e/2LL);
r=produs(r,r);
if(e%2==1LL)r=produs(r,b);
return r;
}
int main()
{
f>>a>>n;/// doar pentru n numar prim a^(-1) = a^(n-1) modulo n
g<<putere(a,n-2);
return 0;
}
