当前位置:网站首页>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;
}边栏推荐
猜你喜欢

ConstraintLayout 的使用

分布式事务(Seata) 四大模式详解

7-18 finding the single root of polynomial by dichotomy

Sub GHz wireless solution Z-Wave 800 Series zg23 SOC and zgm230s modules

如何查询淘宝天猫的宝贝类目

泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东
![洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解](/img/89/da1a3a38e02671628f385de0f30369.png)
洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解

天谋科技 Timecho 完成近亿元人民币天使轮融资,打造工业物联网原生时序数据库

Sword finger offer 28 Symmetric binary tree

tonybot 人形机器人 首次开机 0630
随机推荐
MySQL multi table query subquery
7-10 stack of hats (25 points) (C language solution)
Sub GHz wireless solution Z-Wave 800 Series zg23 SOC and zgm230s modules
Happy capital new dual currency fund nearly 4billion yuan completed its first account closing
7-22 tortoise and rabbit race (result oriented)
Time conversion ()
[qingniaochangping campus of Peking University] in the Internet industry, which positions are more popular as they get older?
7-3 count the number of words in a line of text
Accelerating strategy learning using parallel differentiable simulation
Zzuli:1040 sum of sequence 1
亚马逊、速卖通、Lazada、Shopee、eBay、wish、沃尔玛、阿里国际、美客多等跨境电商平台,测评自养号该如何利用产品上新期抓住流量?
光猫超级账号密码、宽带账号密码 获取
Thread. Sleep and timeunit SECONDS. The difference between sleep
Comprehensive evaluation of good-looking, easy-to-use and powerful handwriting note taking software: notability, goodnotes, marginnote, handwriting, notes writers, collanote, collanote, prodrafts, not
Plane vector addition
FPGA blocking assignment and non blocking assignment
Tonybot humanoid robot starts for the first time 0630
Solr series of full-text search engines - basic principles of full-text search
Thinking about the arrangement problem in the backtracking problem (leetcode questions 46 and 47)
adc128s022 ADC verilog设计实现