Pagini recente » Borderou de evaluare (job #1566511) | Borderou de evaluare (job #2698821) | Borderou de evaluare (job #1510949) | Borderou de evaluare (job #3324999) | Cod sursa (job #3302575)
#include <iostream>
#include <vector>
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int pow(int a, int b) {
int r = 1;
for (int i = 0; i < b;i++) {
r *= a;
}
return r;
}
unsigned long long fast_pow(int a, int b) {
if (b % 2 == 0) {
return pow(a * a, b / 2);
}
else {
return a * pow(a * a, ((b - 1) / 2));
}
}
// ! impar: a^b = a * pow(a*a,(b-1)/2)
// ! par: a^b = pow(a*a,b/2)
// ! 2^4 = (2*2)^2= 4^2 = pow(16,1) = 16 * pow(16*16, 0)
// ! 2^7 =
// ! 2^7 = 2 * 2^6 =
int main(void) {
unsigned long long n, p;
f >> n >> p;
unsigned long long r = fast_pow(n, p);
g << r % MOD;
return 0;
}