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组测试数据:
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; } }
相关文章推荐
- 1.m分解阶乘之和
- 2.几种递推数
- 3.欧拉函数
- 4.快速幂模m算法
- 5.扩展欧几里得&&中国剩余定理
- 6.数论_web
- Project Euler Problem 387 - Harshad Numbers - 深度优先
- 编程之美2015初赛A
- 数论题集
- 原根
- 阶与原根学习笔记
- HDU 1299 Diophantus of Alexandria
- Leftmost Digit(HDU 1060)
- Rightmost Digit(HDU 1061)
- Python-在奇数中寻找素数
- ZOJ 2674 Strange Limit 欧拉定理
- LeetCode-Palindrome Number
- 组合数求模总结
- 【数论】组合数求模
- [BZOJ1041][HAOI2008][数学乱搞]圆上的整点