Cod sursa(job #609516)
Utilizator | Andrei Geogescu mening12001 | Data | 21 august 2011 20:46:31 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include<iostream.h>
#include<fstream.h>
int main()
{ifstream f("lgput.in");
ofstream h("lgput.out");
long long n,k,p=1;
f>>n>>k;
if(k>0)
while(k>=1)
{if(k&1)
{p=p*n;
k=k-1;}
n=n*n;
k=k>>1;}
else
if(k==0)
h<<1;
else
while(k>=1)
{if(k&1)
{p=p*(1/n);
k=k-1;}
n=(1/n)*(1/n);
k=k>>1;}
h<<p%1999999973;
return 0;}