Cod sursa(job #1006474)
| Utilizator | Data | 7 octombrie 2013 09:31:00 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include<fstream>
using namespace std;
ifstream is("lgput.in");
ofstream os("lgput.out");
int M(1999999973);
int power(int N, int P)
{
if(P==0) return 1;
if(P==1) return N;
long long aux = power(N,P/2);
aux = (aux*aux) % M;
if(P%2==1) aux=(aux*N)%M;
return aux;
}
int main()
{
int baza,exponentul;
is >> baza >> exponentul;
os << power(baza,exponentul);
}
