Cod sursa(job #2461522)
Utilizator | Data | 25 septembrie 2019 19:48:11 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long fc(long long a, long long b)
{
if (b == 1)
return a;
if (b == 0)
return 1;
if (b % 2 == 1)
return (a * fc(a, b - 1));
return fc(a * a, b / 2);
}
long long a, b;
int main()
{
f >> a >> b;
g << fc(a, b);
return 0;
}