Cod sursa(job #2648549)
| Utilizator | Data | 11 septembrie 2020 14:02:01 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long int exponentiere(int n, int p){
if(p == 1){
return n;
}
if(p % 2 == 1){
return n*exponentiere(n, p-1) % 1999999973;
}
long long int d = exponentiere(n, p/2) % 1999999973;
return d*d % 1999999973;
}
int main(){
int n, p;
fin >> n >> p;
fout << exponentiere(n, p);
return 0;
}
