Cod sursa(job #2746372)
Utilizator | Data | 27 aprilie 2021 19:08:22 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream fin ("lgput.in");
ofstream fout("lgput.out");
int putere(int a, int n){
int p = 1;
while (n >= 1){
if (n % 2)
p = (p * a) % MOD;
a = (a * a) % MOD;
n /= 2;
}
return p;
}
int main(){
int n, p;
fin >> n >> p;
fout << putere(n, p);
return 0;
}