Cod sursa(job #1401481)
| Utilizator | Data | 25 martie 2015 22:01:59 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include <fstream>
using namespace std;
#define IN "lgput.in"
#define OUT "lgput.out"
#define MOD 1999999973ll
#define ll long long
ifstream fin(IN);
ofstream fout(OUT);
ll putere(ll);
ll n, put;
int main(){
fin >>n>>put;
fout <<putere(put)<<'\n';
fout.close();
return 0;
}
ll putere(ll p){
if (!p)
return 1;
ll x;
x=putere(p/2);
x*=x;
x%=MOD;
if (p%2)
return (x*n)%MOD;
return x;
}
