#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <string>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stack>
using namespace std;
#define maxSize 101
/*
//判定所给的出栈入栈操作序列是否合法 P64 3 2)
int CountI(char seq[],int i)
{
int cnt=0;
for(int j=0;j<=i;j++)
{
if(seq[j]=='I')
{
cnt++;
}
}
return cnt;
}
int CountO(char seq[],int i)
{
int cnt=0;
for(int j=0;j<=i;j++)
{
if(seq[j]=='O')
cnt++;
}
return cnt;
}
int Judge(char seq[],int n)
{
for(int i=0;i<n;i++)
{
if(seq[i]=='O'&&i!=n-1)
{
if(CountO(seq,i)>CountI(seq,i))
{
return 0;
}
}
else if(seq[i]=='O'&&i==n-1)
{
if(CountI(seq,i)!=CountO(seq,i))
{
return 0;
}
}
}
return 1;
}
int main()
{
int n;
cin>>n;
char seq[maxSize];
for(int i=0;i<n;i++)
cin>>seq[i];
int d=Judge(seq,n);
cout<<d<<endl;
}
8
I I I O O I O O
1
*/
/*
//判断单链表的字符是否中心对称 P64 4
typedef struct LNode
{
char data;
LNode *next;
}LNode;
int Judge(LNode *l)
{
char stack[maxSize];
int top=-1;
LNode *p;
p=l;
while(p->next)
{
stack[++top]=p->next->data;
p=p->next;
}
while(l->next)
{
char s=l->next->data;
if(s!=stack[top])
{
return 0;
}
top--;
l=l->next;
}
return 1;
}
int main()
{
LNode *l=(LNode*)malloc(sizeof(LNode));
l->next=NULL;
int n;
cin>>n;
char t;
LNode *p=l;
for(int i=0;i<n;i++)
{
cin>>t;
LNode *q=(LNode*)malloc(sizeof(LNode));
q->data=t;
p->next=q;
p=q;
p->next=NULL;
}
while(l->next)
{
cout<<l->next->data<<" ";
l=l->next;
}
int d=Judge(l);
cout<<d;
}
5
a s d s a
1
*/
/*
//共享栈 P64 5
int top1=-1;
int top2=maxSize;
void push1(int stack[],int d)
{
if(top2-top1!=1)
stack[++top1]=d;
}
void pop1(int stack[],int &d)
{
if(top1!=-1)
{
d=stack[top1];
top1--;
}
}
void push2(int stack[],int d)
{
if(top2-top1!=1)
stack[--top2]=d;
}
void pop2(int stack[],int &d)
{
if(top2!=maxSize)
{
d=stack[top2];
top2++;
}
}
int main()
{
int stack[maxSize];
push1(stack,1);
push2(stack,2);
push1(stack,3);
push2(stack,4);
int d;
pop2(stack,d);
cout<<d;
}
*/
/*
//循环队列中用tag表示队列满或空 P78 1
typedef struct Queue
{
int data[maxSize];
int tag;
int front,rear;
}Queue;
void EnQueue(Queue *q,int d)
{
if(q->front==q->rear&&q->tag==1)
return;
else
{
q->data[q->rear]=d;
q->rear=(q->rear+1)%maxSize;
q->tag=1;
}
}
void DeQueue(Queue *q,int &d)
{
if(q->front==q->rear&&q->tag==0)
return;
else
{
d=q->data[q->front];
q->front=(q->front+1)%maxSize;
q->tag=0;
}
}
*/
/*
//利用队列和栈实现队列中的元素逆置 P78 2
typedef struct Queue
{
int data[maxSize];
int front,rear;
}Queue;
void Reverse(Queue *q)
{
int stack[maxSize];
int top=-1;
while(q->front+1!=q->rear)
{
stack[++top]=q->data[q->front];
q->front=(q->front+1)%maxSize;
}
while(top!=-1)
{
q->data[q->rear]=stack[top--];
q->rear=(q->rear+1)%maxSize;
}
}
*/
/*
//判断表达式中的括号是否配对 P87 1
int main()
{
string ch;
cin>>ch;
char stack[maxSize];
int top=-1;
for(int i=0;ch[i]!='\0';i++)
{
if(ch[i]=='('||ch[i]=='['||ch[i]=='{')
{
stack[++top]=ch[i];
}
else if(ch[i]==')')
{
char s=stack[top--];
if(s!='(')
break;
}
else if(ch[i]==']')
{
char s=stack[top--];
if(s!='[')
break;
}
else if(ch[i]=='}')
{
char s=stack[top--];
if(s!='{')
break;
}
}
if(top!=-1)
{
cout<<"不配对"<<endl;
}
else
{
cout<<"配对"<<endl;
}
}
*/
/*
//调整车厢的顺序使得软座在硬座之前 P87 2
void Adjust(char ch[],char ch2[],int n)
{
char stack[maxSize];
int top=-1;
int k=0;
for(int i=0;i<n;i++)
{
if(ch[i]=='H')
{
stack[++top]='H';
ch2[k++]='I';
}
}
while(top!=-1)
{
ch2[k++]='O';
top--;
}
}
int main()
{
int n;
char ch[maxSize];
cin>>n;
for(int i=0;i<n;i++)
cin>>ch[i];
char ch2[maxSize];
Adjust(ch,ch2,n);
for(int i=0;i<n;i++)
cout<<ch2[i]<<" ";
}
*/
//利用栈来实现递归函数的非递归 P88 3 ???
double Calu(int x,int n)
{
if(n==0)
return 1;
else if(n==1)
return 2*x;
double stack[maxSize];
int top=-1;
stack[++top]=1;
stack[++top]=2*x;
n-=2;
while(n)
{
double d1=stack[top--];
double d2=stack[top];
double d=2*x*d2-2*(n-1)*d1;
stack[++top]=d;
n--;
}
return stack[top];
}
int main()
{
int x,n;
cin>>x>>n;
int d=Calu(x,n);
cout<<d;
}
//模拟 P88 4