c++兔子问题(斐波那契数列)

欢迎收看大型纪录片之写兔子问题

上代码

先骗个分

限一百一十位

#include<iostream>
using namespace std;
int main() {
    int T;
    cin>>T;
    if (T == 1) {
    cout<<"1";
    } else if (T == 2) {
    cout<<"1";
    }  else if (T == 3) {
    cout<<"3";
    } else if (T == 4) {
    cout<<"5";
    } else if (T == 5) {
    cout<<"8";
    } else if (T == 6) {
    cout<<"13";
    } else if (T == 7) {
    cout<<"21";
    } else if (T == 8) {
    cout<<"34";
    } else if (T == 9) {
    cout<<"55";
    } else if (T == 10) {
    cout<<"89";
    } else if (T == 11) {
    cout<<"144";
    } else if (T == 12) {
    cout<<"233";
    } else if (T == 13) {
    cout<<"377";
    } else if (T == 14) {
    cout<<"610";
    } else if (T == 15) {
    cout<<"987";
    } else if (T == 16) {
    cout<<"1597";
    } else if (T == 17) {
    cout<<"2584,";
    } else if (T == 18) {
    cout<<"4181";
    } else if (T == 19) {
    cout<<"6765";
    } else if (T == 20) {
    cout<<"10946";
    } else if (T == 21) {
    cout<<"17711";
    } else if (T == 22) {
    cout<<"28657";
    }else if (T == 23) {
    cout<<"46368";
    }else if (T == 24) {
    cout<<"75025";
    }else if (T == 25) {
    cout<<"121393";
    }else if (T == 26) {
    cout<<"196418";
    }else if (T == 27) {
    cout<<"31781";
    }else if (T == 28) {
    cout<<"514229";
    }else if (T == 29) {
    cout<<"832040";
    }else if (T == 30) {
    cout<<"1346269";
    } else if (T == 31) {
	cout<<"2178309";
	}else if (T == 32) {
	cout<<"3524578";
	}else if (T == 33) {
	cout<<"5702887";
	}else if (T == 34) {
	cout<<"9227465";
	}else if (T == 35) {
	cout<<"14930352";
	}else if (T == 36) {
	cout<<"24157817";
	}else if (T == 37) {
	cout<<"39088169";
	}else if (T == 38) {
	cout<<"63245986";
	}else if (T == 39) {
	cout<<"102334155";
	}else if (T == 40) {
	cout<<"165580141";
	}else if (T == 41) {
	cout<<"267914296";
	}else if (T == 42) {
	cout<<"433494437";
	}else if (T == 43) {
	cout<<"701408733";
	}else if (T == 44) {
	cout<<"1134903170";
	}else if (T == 45) {
	cout<<"1836311903";
	}else if (T == 46) {
	cout<<"2971215073";
	}else if (T == 47) {
	cout<<"4807526976";
	}else if (T == 48) {
	cout<<"7778742049";
	}else if (T == 49) {
	cout<<"12586269025";
	}else if (T == 50) {
	cout<<"20365011074";
	}else if (T == 51) {
	cout<<"32951280099";
	}else if (T == 52) {
	cout<<"53316291173";
	}else if (T == 53) {
	cout<<" 86267571272";
	}else if (T == 54) {
	cout<<"139583862445";
	}else if (T == 55) {
	cout<<"225851433717";
	}else if (T == 56) {
	cout<<"365435296162";
	}else if (T == 57) {
	cout<<"591286729879";
	}else if (T == 58) {
	cout<<" 956722026041";
	}else if (T == 59) {
	cout<<"1548008755920";
	}else if (T == 60) {
	cout<<"2504730781961";
	}else if (T == 61) {
	cout<<"4052739537881";
	}else if (T == 62) {
	cout<<" 6557470319842";
	}else if (T == 63) {
	cout<<" 10610209857723";
	}else if (T == 64) {
	cout<<"17167680177565";
	}else if (T == 65) {
	cout<<"27777890035288";
	}else if (T == 66) {
	cout<<"44945570212853";
	}else if (T == 67) {
	cout<<"72723460248141";
	}else if (T == 68) {
	cout<<"117669030460994";
	}else if (T == 69) {
	cout<<" 190392490709135";
	}else if (T == 70) {
	cout<<"308061521170129";
	}else if (T == 71) {
	cout<<"498454011879264";
	}else if (T == 72) {
	cout<<" 806515533049393";
	}else if (T == 73) {
	cout<<" 1304969544928657";
	}else if (T == 74) {
	cout<<"2111485077978050";
	}else if (T == 75) {
	cout<<"3416454622906707";
	}else if (T == 76) {
	cout<<"5527939700884757";
	}else if (T == 77) {
	cout<<" 8944394323791464";
	}else if (T == 78) {
	cout<<"14472334024676221";
	}else if (T == 79) {
	cout<<" 23416728348467685";
	}else if (T == 80) {
	cout<<"37889062373143906";
	}else if (T == 81) {
	cout<<"61305790721611591";
	}else if (T == 82) {
	cout<<"99194853094755497";
	}else if (T == 83) {
	cout<<"160500643816367088";
	}else if (T == 84) {
	cout<<"259695496911122585";
	}else if (T == 85) {
	cout<<"420196140727489673";
	}else if (T == 86) {
	cout<<"679891637638612258";
	}else if (T == 87) {
	cout<<"1100087778366101931";
	}else if (T == 88) {
	cout<<"1779979416004714189";
	}else if (T == 89) {
	cout<<"2880067194370816120";
	}else if (T == 90) {
	cout<<"4660046610375530309";
	}else if (T == 91) {
	cout<<"7540113804746346429";
	}else if (T == 92) {
	cout<<"12200160415121876738";
	}else if (T == 93) {
	cout<<"19740274219868223167";
	}else if (T == 94) {
	cout<<"31940434634990099905";
	}else if (T == 95) {
	cout<<"51680708854858323072";
	}else if (T == 96) {
	cout<<"83621143489848422977";
	}else if (T == 97) {
	cout<<"135301852344706746049";
	}else if (T == 98) {
	cout<<"218922995834555169026";
	}else if (T == 99) {
	cout<<"354224848179261915075";
	}else if (T == 100) {
	cout<<"573147844013817084101";
	}else if (T == 101) {
	cout<<"927372692193078999176";
	}else if (T == 102){
	cout<<"1500520536206896083277";
	}else if (T == 103){
	cout<<"2427893228399975082453";
	}else if (T == 104){
	cout<<"3928413764606871165730";
	}else if (T == 105){
	cout<<"6356306993006846248183";
	}else if (T == 106){
	cout<<"10284720757613717413913";
	}else if (T == 107){
	cout<<" 16641027750620563662096";
	}else if (T == 108){
	cout<<"26925748508234281076009";
	}else if (T == 109){
	cout<<"43566776258854844738105";
	}else if (T == 110){
	cout<<"70492524767089125814114";
	}
    return 0;
}

正片开始

由于此题过于简单

直接奉上代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a=1,b=1,c;
	int n;//项数 
	cin>>n;//输入项数 
	for(int i=3;i<=n;i++)//由于变量“”a“b”初始值是一,所以“i”从三开始 
	{
		c=a+b;//计算下一项 
		a=b;//将“b”向前移动一项
		b=c;//将“c”向前移动一项 
	} 
	 cout<<c;//输出 
	 return 0;
}

再考考大家

☞ 一道题(需登录luogu)

↓↓↓参考答案↓↓↓

#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a=1,b=1,c;
	long long n;//项数 
	cin>>n;//输入项数 
	if(n==0){
		cout<<"0.00";
		return 0; 
	}
	for(int i=3;i<=n;i++)//由于变量“”a“b”初始值是一,所以“i”从三开始 
	{
		c=a+b;//计算下一项 
		a=b;//将“b”向前移动一项
		b=c;//将“c”向前移动一项 
	}
	cout<<c<<".00";//输出 
	return 0;
} 

好啦!

这期就到这里了

记得点赞

散会

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值