Cod sursa(job #1264219)
Utilizator | Data | 15 noiembrie 2014 16:51:49 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
long long c=1999999973;
long long f(long long a,long long b)
{
if(b==0) return 1;
else if(b==1) return a%c;
if(b%2==0) {long long aux=f(a,b/2); return (aux*aux)%c;}
if(b%2==1) return (f(a,b-1)*a)%c;
}
int main()
{
long long n,p;
in>>n>>p;
out<<f(n,p);
}