Cod sursa(job #398227)
| Utilizator | Data | 18 februarie 2010 11:46:31 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.4 kb |
#include<iostream>
#include <fstream>
using namespace std;
const int m = 1999999973;
unsigned long long n ,p;
void prel()
{
ifstream f;
ofstream g;
g.open("lgput.out");
f.open("lgput.in");
f>>n>>p;
unsigned long long sol=1;
for (int i=0; (1<<i)<=p; i++)
{
if ((1<<i) & p )
sol=(sol*n)%m;
n=(n*n)%m;
}
g<<sol;
g.close();
f.close();
}
void main()
{
prel();
}