兔子

来源:互联网 发布:潜在因子推荐算法 编辑:程序博客网 时间:2024/04/27 01:13

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 of pairs of rabbits in each month is called Fibonacci sequence. But when m<>2, the problem seems 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 assume that none of the rabbits dies in this period.

Input

The input may have multiple test cases. 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 33 51 1000 0

Sample Output

591267650600228229401496703205376
 
使用大数模板
int main(){    //freopen("b.txt","r",stdin);  int d,m,i;BigNum r[105];while(scanf("%d %d",&m,&d)==2&&d+m)    {        for(i=1;i<=m;i++)                     r[i]=i+1;           //当m<=d时,成年兔子数目不变,每月产一对
        for(i=m+1;i<=d;i++)
            r[i]=r[i-1]+r[i-m];        //当m>d之后,当月兔子总数等于上月兔子总数加上m个月前的兔子总数
 
        r[d].print();    }return 0;}

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 高德NaviInfo 安卓蓝牙发送信息 clj.fastble 先采用队列求一条最短迷宫路径长度minlen,再采用栈求所有长度为minlen的最短迷宫路径 iOS蓝牙 pycharm激活 shadowsocks下载 shadowsocks下载 开源沙龙 C++程序设计从键盘中输入两个整数,求这两个整数的最大公约数和最小公倍数。 江南大学五部曲 centos搭建ss 算法之美_源代码发布(8) understand halfaSPIclockcycleproducesaclockedge 贪心算法活动 TRIZ系列-创新原理-17 朴素贝叶斯分类 王者荣耀金币 探索性数据分析演示 治安防控 治安 TRIZ系列-创新原理-19 TRIZ系列-创新原理-20 利用图像的平移、旋转、缩放、镜像等空间几何变换实现对图像的自适应缩放、几何变换等特效 利用图像的平移、旋转、缩放、镜像等空间几何变换实现对图像的几何变换等特效 [Err]1005-Can\'tcreatetable\'item4.#sql-1238_2c\'( SAPFICO财务成本知识 财务管理分析(希金斯:第八版) 图像解压 巜人民曰报》采访张文宏,陈尔真 linux上服务器如何转发设置 图像的自适应缩放、几何变换等特效 千讯网络下载 Gsensor调试 MTKGsensor调试 展讯Gsensor调试 webrtcaec webrtc http://download.csdn.net/detail/aa1000777/7251959 分数相加和恰好为1