Pagini recente » Cod sursa (job #123754) | Cod sursa (job #2505649) | Cod sursa (job #1276999) | Cod sursa (job #1355616) | Cod sursa (job #584206)
Cod sursa(job #584206)
#include <fstream>
#include <cmath>
#include <iostream>
using namespace std;
#define m 1999999973
unsigned long long int p, x, x1, x2;
int main()
{
ifstream fin("lgput.in");
ofstream fout("lgput.out");
fin >> x >> p;
x = x % m;
if(p > 1)
{
x1 = 1;
x2 = x;
while(p != 0)
{
if(p % 2 == 1)
{
x1 = x1 * x % m;
p--;
}
else
{
x2 = x2 * x2 % m;
p = p / 2;
}
}
fout << x1 * x2 % m;
}
else
{
if(p == 0)
fout << 1;
else
fout << x;
}
fout.close();
fin.close();
return 0;
}