Cod sursa(job #3002417)
Utilizator | Data | 14 martie 2023 19:03:32 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
#define MOD 1999999973
std::ifstream fin("lgput.in");
std::ofstream fout("lgput.out");
long long int power(int n, int p){
long long int res = 1;
while(p){
if(p % 2 == 1)
res *= 1LL*n, res %= MOD;
n = 1LL*n * n; n %= MOD;
p /= 2;
}
return res % MOD;
}
int n, p;
int main(){
fin >> n >> p;
fout << power(n, p);
}