当前位置:网站首页>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;
}边栏推荐
- Doris学习笔记之数据表的创建
- 天谋科技 Timecho 完成近亿元人民币天使轮融资,打造工业物联网原生时序数据库
- tonybot 人形機器人 紅外遙控玩法 0630
- Tiantu investment sprint Hong Kong stocks: asset management scale of 24.9 billion, invested in xiaohongshu and Naixue
- 556. 下一个更大元素 III : 简单构造模拟题
- ZABBIX saves the page blank after adding calculated items
- NPM install is stuck with various strange errors of node NPY
- Get permissions dynamically
- J-luggage lock of ICPC Shenyang station in 2021 regional games (simple code)
- Programming language: the essence of type system
猜你喜欢

基因家族特征分析 - 染色体定位分析

表单文本框的使用(一) 选择文本

Tonybot Humanoïde Robot Infrared Remote play 0630
![[qingniaochangping campus of Peking University] in the Internet industry, which positions are more popular as they get older?](/img/f6/fe61c84f289f0e74a45946dac687a6.jpg)
[qingniaochangping campus of Peking University] in the Internet industry, which positions are more popular as they get older?

Tonybot humanoid robot infrared remote control play 0630

Showmebug entered Tencent conference, opening the era of professional technical interview

puzzle(016.3)千丝万缕

Jiuyi cloud black free encryption free version source code

Analysis of gene family characteristics - chromosome location analysis

Eight sorts
随机推荐
Timecho of Tianmou technology completed an angel round financing of nearly 100 million yuan to create a native timing database of the industrial Internet of things
Stop asking yourself if you are suitable for software testing
中感微冲刺科创板:年营收2.4亿净亏1782万 拟募资6亿
SSH access control, blocking the IP when logging in repeatedly to prevent brute force cracking
7-19 check denomination (solve binary linear equation)
Analysis of gene family characteristics - chromosome location analysis
The mail function of LNMP environment cannot send mail
Time conversion ()
tonybot 人形机器人 首次开机 0630
Mongodb index
洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解
DDK for XP
Leetcode (4) -- find the median of two positively ordered arrays
全文检索引擎Solr系列—–全文检索基本原理
Detailed explanation of four modes of distributed transaction (Seata)
Special research report on the market of lithium battery electrolyte industry in China (2022 Edition)
Zzuli:1041 sum of sequence 2
Preliminary summary of structure
Common shortcut keys in PCB
7-18 finding the single root of polynomial by dichotomy