Cod sursa(job #2277633)
Utilizator | Data | 6 noiembrie 2018 17:49:14 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.32 kb |
#include <fstream>
using namespace std;
ifstream input("lgput.in");
ofstream output("lgput.out");
#define k 1999999973;
unsigned int N, P, p = 1;
int main()
{
input >> N >> P;
while (N != 0)
{
if (P % 2 == 1)p = (p * N) % k;
N = (N * N) % k;
P /= 2;
}
output << p;
input.close();
output.close();
}