当前位置:网站首页>Zzuli:1055 rabbit reproduction
Zzuli:1055 rabbit reproduction
2022-07-03 14:34:00 【Snake_____】
Title Description
This is an interesting classical mathematical problem , Famous Italian mathematician Fibonacci A question was raised : There's a couple of rabbits , From the day after birth 3 A couple of rabbits are born every month from . The little rabbit grows to the third place 3 Two months later, a couple of rabbits were born every month . According to this rule , Suppose no rabbits died , In the first month, there was a couple of newborn rabbits , Ask No n How many pairs of rabbits in a month ?
Input
Enter the number of months n(1<=n<=44).
Output
Output No n How many pairs of rabbits in a month .
The sample input Copy
3
Sample output Copy
2
Tips
This topic is a classic introduction to recursion : use f(n) It means the first one n Number of rabbits in months , be : f(n) = f(n-1) + Number of rabbits born this month and , Number of rabbits born this month = f(n-2) ( Because every rabbit that existed last month , A new rabbit will be born this month ) therefore ,f(n) = f(n-1) + f(n-2) That's the famous one fabinacci The sequence , The latter is equal to the sum of the first two : 1 1 2 3 5 8.....
#include <stdio.h>
int main()
{
int i,n,a=1,b=1,c;
scanf("%d",&n);
if(n==1)
{
printf("%d",a);
}
else
{
for(i=2;i<n;i++)
{
c=a;
a=a+b;
b=c;
}
printf("%d",a);
}
return 0;
}边栏推荐
- 关于敏捷的一些概念
- Solr series of full-text search engines - basic principles of full-text search
- Special research report on the market of lithium battery electrolyte industry in China (2022 Edition)
- Frequently asked questions: PHP LDAP_ add(): Add: Undefined attribute type in
- Zzuli:1041 sum of sequence 2
- Statistical capital consonants
- 论文分享:Generating Playful Palettes from Images
- 一文了解微分段应用场景与实现机制
- How to query the baby category of tmall on Taobao
- 超简单手机地图开发
猜你喜欢

Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块

MySQL multi table query subquery

556. 下一个更大元素 III

How to query the baby category of tmall on Taobao

Detailed explanation of four modes of distributed transaction (Seata)

编程语言:类型系统的本质

Accelerating strategy learning using parallel differentiable simulation
![Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution](/img/89/da1a3a38e02671628f385de0f30369.png)
Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution

Sword finger offer 28 Symmetric binary tree

必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿
随机推荐
Zzuli:1041 sum of sequence 2
Find specified characters
Protobuf and grpc
MongoDB数据库入门的常用命令
tonybot 人形机器人 首次开机 0630
天谋科技 Timecho 完成近亿元人民币天使轮融资,打造工业物联网原生时序数据库
表单文本框的使用(一) 选择文本
洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解
npm install卡住与node-npy的各种奇怪报错
Tailing rushes to the scientific and Technological Innovation Board: it plans to raise 1.3 billion, and Xiaomi Changjiang is the shareholder
retrofit
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Solr series of full-text search engines - basic principles of full-text search
Luogu p3065 [usaco12dec]first! G problem solution
How to query the baby category of tmall on Taobao
7-10 stack of hats (25 points) (C language solution)
7-17 crawling worms (break exercise)
7-6 mixed type data format input
1017 a divided by B (20 points)
String sort