// file: radicalPower.cpp

#include <iostream.h>
#include <math.h>

struct list {
  int data;
  struct list * prev;
}; //struct list

int main () {

  int p;
  long val = 1;

  // get the necessary input

  cout << "enter the power...";
  cin >> p;
  cout << "2^" << p << " = "; 

  struct list * l = NULL;
 
  // we decompose the given power and store the
  // results in a backwards linked list
 
  while (p) {
    if (p%2) {
      p /= 2;
      struct list cur;
      cur.data = 2;
      cur.prev = l;
      l = &cur;
    } else {
      if (p) {
        p -=1;
        struct list cur;
        cur.data = 1;
        cur.prev = l;
        l = &cur;   
      } //if (p)
    } //if (p%2)
  } //while (p)

  // using the previously storeg list, we evaluate
  // the value of the power
 
  while (l) {
    if (l->data == 2) {
      l = l->prev;
      val = pow (val,2);
    } //if (l->data == 1)
    if (l->data == 2) {
      l = l->prev;
      val *=2;
    } //if (l->data == 2)
  } //while (l->data)
 
  // print the results
  cout << val;
 
  return (0);
} //int main() 
