Cod sursa(job #2165760)
| Utilizator | Data | 13 martie 2018 13:33:01 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#include <iostream>
#include <fstream>
#define mod 1999999973
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
int nr, p;
int putere ( int nr, int p )
{
if ( p == 0 )
{
return 1;
}
else
{
int x = putere ( nr, p / 2 );
if ( p % 2 == 0 )
{
return ( ( x % mod ) * ( x % mod ) ) % mod;
}
else
{
return ( ( x % mod ) * ( x % mod ) * ( nr % mod ) ) % mod;
}
}
}
int main()
{
fin >> nr;
fin >> p;
fout<< putere( nr, p );
}
