斐波那契数列的变形
#include <iostream>
using namespace std;
int Fbi(int n)
{
if(n == 0)
{
return 11;
}
else if(n == 1)
{
return 7;
}
else
{
return Fbi(n-1) + Fbi(n-2);
}
}
int main()
{
int n;
while(cin >> n)
{
if(Fbi(n)%3 == 0)
{
cout << "Yes"<<endl;
}
else
{
cout << "No"<<endl;
}
}
return 0;
}
用递归的结果就是Memory Limit Exceeded
,太占空间了。。。
于是将递归改为迭代。
后来才发现把F(1)和F(0)的值给弄反了,而且输出的字符串全部是小写的
#include <iostream>
using namespace std;
<