Cod sursa(job #1392575)
| Utilizator | Data | 18 martie 2015 18:58:01 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
#define MOD 1999999973
#define LL long long
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
LL n,p;
void read(){
f>>n>>p;
}
LL lgput(LL nr,LL p){
if(p == 0)
return 1;
if(p == 1)
return nr;
if(p%2 == 0){
LL tmp = lgput(nr,p/2);
return (tmp*tmp)%MOD;
}
return (nr*lgput(nr,p-1))%MOD;
}
void solve(){
g<<lgput(n,p);
}
int main()
{
read();
solve();
return 0;
}
