Description
我们可爱的KK遇到了一道数学难题:对于一条长为N(1≤N≤10^18 )米的钢管,最多可以锯成几根小钢管,使得锯成的钢管互不相等且均不能围成三角形
Input
第一行一个数T(1≤T≤10),表示数据组数。
接着T行,每行一个整数N(1≤N≤10^18 ),表示钢管的长度。
Output
对于每一个数据输出一个整数,表示可以锯成的钢管数。
Sample Input
1
6
Sample Output
3
Solution
简单题,问题变成n最多能包含斐波那契数列的前几项
Code
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
int T;
ll n,f[99];
f[1]=1,f[2]=2;
for(int i=3;i<88;i++)f[i]=f[i-1]+f[i-2];
scanf("%d",&T);
while(T--)
{
scanf("%I64d",&n);
int res=1;
for(;res<88&&f[res]<=n;res++)n-=f[res];
printf("%d\n",res-1);
}
return 0;
}