Pagini recente » Cod sursa (job #1961186) | Cod sursa (job #2536596) | Cod sursa (job #2898238) | Cod sursa (job #1525524) | Cod sursa (job #1906572)
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
const int mod = 1999999973;
long long N,P;
long long pw(long long,long long);
int main() {
in>>N>>P;
out<<pw(N,P);
in.close();out.close();
return 0;
}
long long pw(long long x,long long e) {
x = x % mod;
if (e == 0) {return 1;}
if (e == 1) {return x;}
if (e%2 == 1) {return ( x * pw(x*x, (e-1)/2) ) % mod ;}
if (e%2 == 0) {return pw(x * x, e / 2) % mod;}
}
/*
#include <iostream>
#include <map>
#include <cstring>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
const int mod = 1999999973;
long long N,P;
long long lgput(long long, long long);
int main() {
in>>N>>P;
out<<lgput(N,P);
in.close();out.close();
return 0;
}
long long lgput(long long x, long long pw) {
int res = 1;
while (pw) {
if (pw % 2 == 1) {
res = (res * x) % mod;
}
x = (x * x) % mod;
pw >>= 1;
}
return res;
}
*/