Cod sursa(job #2527415)
Utilizator | Data | 20 ianuarie 2020 12:13:19 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int mod = 1999999973;
int putere(int b, int p){
if(p == 0)
return 1;
int x = putere(b, p / 2);
if(p % 2 == 0) {
return (x * x) % mod;
}
else {
return (b * x * x) % mod;
}
}
int main()
{
int b, p;
fin >> b >> p;
fout << putere(b, p);
}