Cod sursa(job #2050367)
Utilizator | Data | 28 octombrie 2017 09:36:31 | |
---|---|---|---|
Problema | Invers modular | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
#define ll long long
using namespace std;
ll n;
ll putere (ll a, ll b)
{
ll p;
if (b==0) return 0;
if (b==1) return a;
p=putere(a,b/2);
if(b%2==0) return (p*p)%n;
else return (a*p*p)%n;
}
ll x;
int main()
{
ifstream fin ("inversmodular.in");
ofstream fout ("inversmodular.out");
fin>>x>>n;
fout<<(putere(x,n-2));
return 0;
}