iliya785

binary_pow

May 22nd, 2012
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.22 KB | None | 0 0
  1. var a,b:longint;
  2. function pow(a,b:longint):longint;
  3.  begin
  4.   if (b = 0) then pow:=1 else
  5.    if (b mod 2 = 0) then pow:=sqr(pow(a,b shr 1)) else
  6.       pow:=pow(a,b-1)*a
  7.  end;
  8. Begin
  9. read(a,b);
  10. write(pow(a,b));
  11. end.
Advertisement
Add Comment
Please, Sign In to add comment