Rabbit

Rabbit

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 49   Accepted Submission(s) : 12
Font: Times New Roman | Verdana | Georgia
Font Size:  

Problem Description

The rabbits have powerful reproduction ability. One pair of adult rabbits can give birth to one pair of kid rabbits every month. And after m months, the kid rabbits can become adult rabbits.
As we all know, when m=2, the sequence of the number pairs of rabbits in each month is called Fibonacci seqence. But when m<>2, the problem sees not so simple. You job is to calculate after d months, how many pairs of the rabbits are there if there is exactly one pair of adult rabbits initially. You may assure that none of the rabbits dies in this period.

Input

The input may have multiple test case. In each test case, there is one line having two integers m(1<=m<=10), d(1<=d<=100), m is the number of months after which kid rabbits can become adult rabbits, and d is the number of months after which you should calculate the number of pairs of rabbits. The input will be terminated by m=d=0.

Output

You must print the number of pairs of rabbits after d months, one integer per line.

Sample Input

2 3
3 5
0 0

Sample Output

5
9
#include<iostream>
#include<sstream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#define maxn 2100
using namespace std;


struct bign
{
    int len,s[maxn];


    bign()
    {
        memset(s,0,sizeof(s));
        len=1;
    }


    bign(int num) {*this=num;}


    bign(const char* num){*this=num;}


    bign operator = (int num)
    {
        char s[maxn];
        sprintf(s,"%d",num);
        *this=s;
        return *this;
    }


    bign operator = (const char* num)
    {
        len=strlen(num);
        int i;
        for(i=0;i<len;i++) s[i]=num[len-i-1]-'0';
        return *this;
    }


    string str() const
    {
        string res = "";
        int i;
        for(i=0;i<len;i++) res=(char)(s[i]+'0')+res;
        if(res=="") res="0";
        return res;
    }


    void clean() {while(len>1&&!s[len-1]) len--;}


    bign operator + (const bign& b) const
    {
        bign c;    c.len=0;
        int i,g;
        for(i=0,g=0;g||i<max(len,b.len);i++)
        {
            int x=g;
            if(i<len) x+=s[i];
            if(i<b.len) x+=b.s[i];
            c.s[c.len++]=x%10;
            g=x/10;
        }
        return c;
    }
};


istream& operator >> (istream &in, bign& x)
{
    string s;
    in >> s;
    x = s.c_str();
    return in;
}


ostream& operator << (ostream &out, const bign& x)
{
    out << x.str();
    return out;
}
int main()
{
    int m,d;
    bign  a[110];
    a[0]=1;
    a[1]=2;
    while(cin>>m>>d)
    { int i;
        if (m==0&&d==0)
            break;
        else
        {
            for (i=1; i<=m-1; i++)
                a[i]=a[i-1]+1;
            for (i=m; i<110; i++)
            {
                if(m>=d)
                    a[i]=a[i-1]+1;


                else
                    a[i]=a[i-1]+a[i-m];
            }
            cout<<a[d]<<endl;
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值