Cod sursa(job #1839641)
| Utilizator | Data | 3 ianuarie 2017 11:44:54 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
using namespace std;
#define mod 1999999973
ifstream f("lgput.in");
ofstream g("lgput.out");
int N , P;
int rez;
long long exp_log ( int n , int p )
{
if ( p == 0 ) return 1;
else if ( p == 1 ) return n;
else
{
if ( p % 2 == 0 ) return exp_log( (n*n)%mod , p/2 );
else return ( n * exp_log( (n*n)%mod , (p-1)/2 ) )%mod ;
}
}
int main()
{
f >> N >> P;
g << exp_log(N,P);
return 0;
}
