Cod sursa(job #3267383)
| Utilizator | Data | 11 ianuarie 2025 11:21:42 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
using namespace std;
int mod = 1000000007;
int exp(int A, int N) {
if (N == 1) return A;
if (N == 0) return 1;
if (N % 2 == 0) {
int aux = exp(A, N / 2);
return (aux * aux) % mod;
}
if (N % 2 == 1) {
int aux = exp(A, N / 2);
return ((aux * aux) % mod * A) % mod;
}
}
int main() {
ifstream cin("lgput.in");
ofstream cout("lgput.out");
int a, b;
cin >> a >> b;
cout << exp(a, b);
return 0;
}