#include <iostream>
using namespace std;
int main() {
int n{};
int a{},b{1},c{1};//函数中有三个未知数,因此定义三个变量
//且b、c分别对应第一项和第二项
cin>>n;
for(int i=3;i<=n;i++)
{
a=b+c;//前两项和得到后一项
b=c;//第一项往后移
c=a;//第二项往后移
//如果你想不清楚,可以参考以下数列:
//1,1,2,3,5,8
//将你的光标逐项往后移,你就能明白我想告诉你什么
}
if(n==1||n==2)//处理特殊的第一项和第二项
{
cout<<1;
return 0;
}
cout<<a;
return 0;
}
// 64 位输出请用 printf("%lld")

京公网安备 11010502036488号