Cod sursa(job #1507839)
| Utilizator | Data | 21 octombrie 2015 22:38:33 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f ("lgput.in");
ofstream g ("lgput.out");
const int modulo=1999999973;
long long p,n,a[10000000],j,i;
long long prod=1,putere;
int main()
{
f >> n >> p;
a[0] = 1;
a[1] = n;
putere = 2;
i = 2;
while(putere <= p){
a[i] = a[i-1] * a[i-1];
putere *= 2;
i++;
}
i--;
putere /= 2;
while(i >= 1){
if(putere <= p){
prod = (prod*a[i]) % modulo;
p -= putere;
}
putere /= 2;
i--;
}
g<<prod;
return 0;
}
