Cod sursa(job #2565284)
| Utilizator | Data | 2 martie 2020 13:20:30 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 60 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("inversmodular.in");
ofstream fout ("inversmodular.out");
long long x,m;
long long exponentiere( int x , int p )
{
if( p == 1 )
return x ;
if( p % 2 == 0 )
{
long long t = exponentiere( x , p / 2 ) ;
return ( 1LL * t * t ) % m ;
}
else
{
long long t = exponentiere( x , p / 2 ) ;
return ( ( 1LL * t * t ) % m ) * x % m ;
}
}
int main()
{ fin >> x >> m ;
fout<< exponentiere( x , m - 2 ) ;
return 0;
}
