Cod sursa(job #471914)
| Utilizator | Data | 21 iulie 2010 19:02:32 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
// ExponentiereRapida.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include "stdio.h"
FILE *f=fopen("lgput.in", "r");
FILE *g=fopen("lgput.out", "w");
long long n, p, sol=1, a=1;
const int m = 1999999973;
int main()
{
fscanf(f, "%lld%lld", &n, &p);
a=n;
for (int i=0; (1<<i)<=p; ++i)
{
if (((1<<i)&p)>0)
sol=(sol*a)%m;
a=(a*a)%m;
}
fprintf(g, "%lld", sol);
return 0;
}
