Cod sursa(job #1954045)
| Utilizator | Data | 5 aprilie 2017 10:17:05 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int MOD = 1999999973;
int Putere(int n, int p);
int main() {
int n, p;
fin >> n >> p;
fout << Putere(n, p);
fin.close();
fout.close();
return 0;
}
int Putere(int n, int p) {
if (p == 1) return n;
int x = Putere(n, p / 2);
x = (1LL * x * x) % MOD;
if (p % 2 == 1) x = (1LL * x * n) % MOD;
return x;
}
