Pagini recente » Cod sursa (job #2534753) | Cod sursa (job #93970) | Cod sursa (job #2330147) | Cod sursa (job #1200070) | Cod sursa (job #3263528)
#include <iostream>
#include <math.h>
#include <fstream>
std::ifstream in("lgput.in");
std::ofstream out("lgput.out");
size_t M = 1999999973;
void fpow(size_t N, size_t P){
size_t result = 1;
size_t aux = N % M;
while(P > 0){
if(P % 2 == 1){
result *= aux % M ;
P--;
continue;
}
P/=2;
aux*=aux % M;
}
out << result % M << std::endl;
}
int main(){
if(!in.is_open()) throw std::runtime_error("File is not opened");
if(!out.is_open()) throw std::runtime_error("File is not opened");
size_t N, P;
in >> N >> P;
fpow(N, P);
}