Cod sursa(job #1873027)
| Utilizator | Data | 8 februarie 2017 19:00:57 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include <bits/stdc++.h>
#define ll long long
#define mod 1999999973
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
ll n, p;
ll lg(ll num, ll put){
if(p == 0) return 1;
ll ans = 1; ll cur = n;
while(put){
if(put % 2 == 1) ans *= num, put--;
if(put) ans *= cur % mod;
cur = cur * cur;
put /= 2;
}
return ans % mod;
}
int main(){
in >> n >> p;
out << lg(n, p);
return 0;
}
