Cod sursa(job #722526)
Utilizator | Badea Corneliu Robert RobertB | Data | 24 martie 2012 17:20:18 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
#include <iostream>
#define MOD 1999999973;
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int N;
int P;
long long rez = 1;
int log(int x, int y)
{
int a;
if(y==1) {
return x%MOD;
}
a = log(x,y/2)%MOD;
if(y % 2 == 1) {
return (x*a*a)%MOD;
}
return (a*a)%MOD;
}
int main()
{
f>>N>>P;
rez = log(N,P) % MOD;;
g<<rez;
}