Cod sursa(job #266141)
Utilizator | Data | 24 februarie 2009 22:19:40 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <fstream>
#define T 1999999973
using namespace std;
int N, P;
int exp( int N, int P )
{
if( P==0 ) return 1;
if( P%2 ) return ( N*exp(N,P-1) )%T;
else return ( N*exp(N,P/2) )%T;
}
int main()
{
ifstream fin("lgput.in");
fin >> N >> P;
fin.close();
ofstream fout("lgput.out");
fout << exp(N,P);
fout.close();
return 0;
}