Cod sursa(job #364998)
| Utilizator | Data | 17 noiembrie 2009 17:07:09 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
std::ifstream fin("lgput.in");
std::ofstream fout("lgput.out");
long long int expmod(long long int a,long long int b,long long int n)
{
int d = 1;
int bin[10];
bin[0] = 0;
while (b)
{
bin[++bin[0]] = b % 2;
b /= 2;
}
for (int i = bin[0]; i >= 1; i--)
{
d = (d * d) % n;
if (bin[i])
d = (d * a) % n;
}
return d;
}
int main()
{
long long a,b;
fin >> a >> b;
fout << expmod(a, b, 1999999973);
}
