Cod sursa(job #3350075)
| Utilizator | Data | 5 aprilie 2026 11:38:07 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
#define MOD 1999999973
ll exp_by_squaring(ll n, ll p){
if(p == 0) return 1;
else if(p < 0) return exp_by_squaring(1/n, -p);
else if(p % 2 == 0) return exp_by_squaring(n*n, p/2);
else return n*exp_by_squaring(n*n, (p-1)/2);
}
int main(){
ll n,p;
fin >> n >> p;
fout << exp_by_squaring(n, p) % MOD ;
return 0;
}