Cod sursa(job #1011123)
| Utilizator | Data | 16 octombrie 2013 11:13:39 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
#include <string.h>
const int n_max = 10001;
const int m = 1999999973;
using namespace std;
int main()
{
unsigned int i, n, p;
long long a, sol = 1;
ifstream fin("lgput.in");
fin>>n>>p;
fin.close();
ofstream fout("lgput.out");
a = n;
for (i = 0; (1<<i) <= p; ++ i)
{
if ( ((1<<i) & p) > 0)
sol= (sol * a) % m;
a=(a * a) % m;
}
fout<<sol<<"\n";
fout.close();
return 0;
}
