A Multiplication Game
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2540 Accepted Submission(s): 1452
Stan wins.
or
Ollie wins.
assuming that both of them play perfectly.
162 17 34012226
Stan wins. Ollie wins. Stan wins.
#include<iostream>
#include<iomanip>
using namespace std;
int fab(int a[],int b[],int len,int c[])
{
int i,temp=0;
for(i=0;i<len;i++)
{
c[i]=(a[i]+b[i]+temp)%10000;
temp=(a[i]+b[i]+temp)/10000;
}
if(temp!=0){c[i]=temp;i++;}
return i;
}
void copy(int a[],int b[],int len)
{
int i;
for(i=0;i<len;i++)
{
a[i]=b[i];
}
}
int main()
{
int a[110],b[110],c[110],n,m,len,j,i;
cin>>n;
while(n--)
{
cin>>m;
memset(a,0,sizeof(int)*110);
memset(b,0,sizeof(int)*110);
memset(c,0,sizeof(int)*110);
a[0]=1;b[0]=1;
len=1;
if(m<3)cout<<"1"<<endl;
else
{
for(i=3;i<=m;i++)
{
len=fab(a,b,len,c);
copy(a,b,len);
copy(b,c,len);
}
cout<<c[len-1];
for(i=len-2;i>=0;i--)
cout<<setfill('0')<<setw(4)<<c[i];
cout<<endl;
}
}
return 0;
}