Cod sursa(job #3298204)
Utilizator | Data | 27 mai 2025 23:33:39 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include<iostream>
#include<fstream>
#define MOD 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long fast_exponentiation(long long x, int n){
if(n == 0) return 1;
else if(n % 2 == 0) return (fast_exponentiation((x * x) % MOD, n / 2) % MOD);
else return (x * fast_exponentiation((x * x) % MOD, n / 2)) % MOD;
}
int main(){
long long n;
int p;
fin >> n >> p;
fout << fast_exponentiation(n, p);
fin.close();
fout.close();
return 0;
}