您的位置:首页 > 其它

KK's Steel bestcoder round 71 hdu 5620(裴波那契)

2016-02-16 12:57 381 查看
Problem Description

Our lovely KK has a difficult mathematical problem:he has a N\left( 1\leq N\leq {10}^{18}\right)N(1≤N≤10

​18

​​ ) meters steel,he will cut it into steels as many as possible,and he doesn’t want any two of them be the same length or any three of them can form a triangle.

Input

The first line of the input file contains an integer T\left( 1\leq T\leq 10\right)T(1≤T≤10), which indicates the number of test cases.

Each test case contains one line including a integer N\left( 1\leq N\leq {10}^{18}\right)N(1≤N≤10

​18

​​ ),indicating the length of the steel.

Output

For each test case, output one line, an integer represent the maxiumum number of steels he can cut it into.

Sample Input

1

6

Sample Output

3

Hint

1+2+3=6 but 1+2=3 They are all different and cannot make a triangle.

6->1 2 3

11->1 2 3 5

19->1 2 3 5 8

。。。。。

很容易看出来是一个裴波那契数列,求出每个刚能切成n段的长度预处理即可。

上代码,查找时都没用二分了,因为这题单个数据量不到100,也只有10组测试数据:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long int ll;
ll a[100];
ll sum[100];
void init()
{
ll x=2,y=1,z;
int cnt=0;
sum[0]=3;
while(cnt<83)
{
z=x+y;
cnt++;
a[cnt]=z;
sum[cnt]=sum[cnt-1]+z;
y=x;
x=z;
}
}
int main()
{
init();
int T;
scanf("%d",&T);
while(T--)
{
ll n;
scanf("%I64d",&n);
if(n<=2)
{
cout<<1<<endl;
continue;
}
if(n<=5)
{
cout<<2<<endl;
continue;
}
int pos;
for(int i=1;i<=83;i++)
{
if(n==sum[i])
{
pos=i;
break;
}
else if(n<sum[i])
{
pos=i-1;
break;
}
}
cout<<pos+2<<endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数论