当前位置:网站首页>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;
}边栏推荐
- Selective sorting
- Four data flows and cases of grpc
- JVM garbage collector
- Puzzle (016.4) domino effect
- Although not necessarily the best, it must be the hardest!
- Comprehensive evaluation of good-looking, easy-to-use and powerful handwriting note taking software: notability, goodnotes, marginnote, handwriting, notes writers, collanote, collanote, prodrafts, not
- SSH访问控制,多次失败登录即封掉IP,防止暴力破解
- LNMP环境mail函数不能发送邮件解决
- Table of mathematical constants by q779
- SSH access control, blocking the IP when logging in repeatedly to prevent brute force cracking
猜你喜欢

puzzle(016.4)多米诺效应

Zhonggan micro sprint technology innovation board: annual revenue of 240million, net loss of 17.82 million, proposed to raise 600million

adc128s022 ADC verilog设计实现

Leetcode (4) -- find the median of two positively ordered arrays

tonybot 人形机器人 查看端口并对应端口 0701

Four data flows and cases of grpc

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

Tonybot Humanoïde Robot Infrared Remote play 0630

Bibit pharmaceutical rushed to the scientific innovation board: annual revenue of 970000, loss of 137million, proposed to raise 2billion

分布式事务(Seata) 四大模式详解
随机推荐
Sendmail can't send mail and it's too slow to send. Solve it
Zzuli:1043 max
Etcd cluster permission management and account password usage
7-16 find the set of integers that meet the given conditions
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
Tailing rushes to the scientific and Technological Innovation Board: it plans to raise 1.3 billion, and Xiaomi Changjiang is the shareholder
Zzuli:1040 sum of sequence 1
SSH访问控制,多次失败登录即封掉IP,防止暴力破解
Use of constraintlayout
使用并行可微模拟加速策略学习
Detailed explanation of four modes of distributed transaction (Seata)
556. 下一个更大元素 III : 简单构造模拟题
Luogu p4047 [jsoi2010] tribal division solution
分布式事务(Seata) 四大模式详解
Zzuli:1041 sum of sequence 2
Selective sorting
Sendmail无法发送邮件及发送过慢解决
7-20 print 99 formula table (format output)
tonybot 人形机器人 定距移动 代码编写玩法
剑指 Offer 28. 对称的二叉树