PROGRAM Exponentiation(Input, Output);
    { Program 4.3 - Compute power(X, Y) = "X raised to power Y"
        using natural exponent. }

    VAR
        Exponent, Y: Integer;
        Base, Result, X: Real;

BEGIN
    Read(Input, X, Y);
    WriteLn(Output, X, ' ', Y);

    Result := 1;
    Base := X;
    Exponent := Y;

    WHILE Exponent > 0 DO
    BEGIN
        { Loop invariant:
            Result * power(Base, Exponent) = power(X, Y), Exponent > 0 }
        WHILE NOT Odd(Exponent) DO          { |                                }
        BEGIN                               { |                                }
            Exponent := Exponent DIV 2;     { |                                }
            Base := Sqr(Base)               { |                                }
        END;                                { |                                }
        Exponent := Exponent - 1;
        Result := Result * Base
    END;
    WriteLn(Output, Result)     { Result = power(X, Y) }
END.
