Cod sursa(job #1401460)
| Utilizator | Data | 25 martie 2015 21:50:25 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 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){
ll x;
if (!p)
return 1;
x=putere(p/2);
if (p%2)
return (x*x*n)%MOD;
return (x*x)%MOD;
}
