Cod sursa(job #317992)
Utilizator | Data | 26 mai 2009 12:57:13 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.31 kb |
#include<fstream.h>
#include<math.h>
int main()
{ifstream q("lgput.in");
ofstream w("lgput.out");
long long m,a,b,ca;
int pos=0;
q>>a>>b;
ca=a;
m=1999999973;
while(b>1)
if(b%2==0)
{b=b/2;
a=a*a;}
else
{pos++;
b--;
b=b/2;
a=a*a;}
for(b=1;b<=pos;b++)
a=a*ca;
w<<a%m;
return 0;}