Cod sursa(job #2214752)
Utilizator | Data | 19 iunie 2018 23:49:54 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
#define NR 1999999973;
int main()
{
int N, P, i;
long long x, y = 1;
fin >> N >> P;
x = N;
for (i = 0; (1 << i) <= P; i++) {
if ((1 << i) & P)
y = y * x;
x = x * x;
}
fout << y % NR;
}