Cod sursa(job #744546)
| Utilizator | Data | 8 mai 2012 23:32:12 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int main()
{
long long a,b;
fin>>a>>b;
long long d=1;
long long bin[10000];
bin[0]=0;
while(b)
{
bin[++bin[0]]=b%2; b/=2;
}
for(int i=bin[0];i>=1;i--)
{
d=(d*d)%MOD;
if(bin[i])
d=(d*a)%MOD;
}
fout<<d<<'\n';
fin.close();
return 0;
}
