该序列的前两个数字为一,每个元素与前两个元素的总和相同
输入n然后输出答案
例如输入10
因为
1123581321
第十个数为一
所以输出为一
#include<iostream>
using namespace std;
int main()
{
int n,a=1,b=1,t,i;
int d[100] = {0};
cin >> n;
if (n<3)
{
cout << 1 << endl;
return 0;
}
n-=2;
while (true)
{
t = a+b;
a = b;
b = t;
// cout << t<< "-";
for (i = 0; t>0; i++)
{
d[i] = t%10;
t /= 10;
}
if (n<=i)
{
cout << d[i-n];
return 0;
}
n -= i;
}
return 0;
}
如有帮助,望采纳!谢谢!