Cod sursa(job #515268)
Utilizator | Data | 20 decembrie 2010 21:41:13 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
using namespace std;
int main()
{
const unsigned long mod = 1999999973;
unsigned long long a, b, p = 1;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
fin >> a >> b;
while (b > 0) {
if (b % 2 == 1) {
p = p * a % mod;
}
a = a * a % mod;
b /= 2;
}
fout << p;
fin.close();
fout.close();
return 0;
}