Cod sursa(job #2439763)
Utilizator | Data | 16 iulie 2019 19:48:56 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int m=1999999973;
int main()
{
int n, p=1, x;
f>>x>>n;
while (n > 0)
{
if (n % 2 == 0)
{
n = n/2;
x = x*x;
}
else // n % 2 == 1
{
n = n-1;
p = p*x;
}
}
g<< p % m;
return 0;
}