斐波那契数列
2014-02-07 15:07
113 查看
描述:请实现一个可以显示斐波那契列表的activity。
1. 请写一个仅有一个列表页面的Android应用
2. 列表从0开始,从小到大,每行显示一个斐波那契数字
列表的第n行显示F(n3),至少显示到 F(603)
1. 请写一个仅有一个列表页面的Android应用
2. 列表从0开始,从小到大,每行显示一个斐波那契数字
列表的第n行显示F(n3),至少显示到 F(603)
#include "stdafx.h" #include <iostream> #include <Windows.h> #include <time.h> #include "fibo.h" using namespace std; static long fib(long a[], long b[]); int _tmain(int argc, _TCHAR* argv[]) { time_t time1,time2; time(&time1); //SYSTEMTIME time,time1; //GetSystemTime(&time); long a[5400]={0},o,x=1,temp[5400]={0} ,temp1[5400]={0} ,temp2[5400]={0},temp3[5400]={0}; temp2[5399]=1; long l = 0; for(long j=1; j<216001; j++){ /*for(long i=0; i<5400;i++){ temp[i] =temp2[i]; }*/ l=fib(temp1,temp2); //for(long i=0; i<5400; i++){ // temp1[i] = temp[i]; //} /*for(long i=0; i<5400; i++){ temp2[i]=temp3[i]; }*/ if(j==x*x*x){ bool d = false; for(long i=l; i<=5399; i++){ if(!d){ if(temp2[i]!=0) d=true; if(!d) continue; } long t = temp2[i]; int w; for(w = 0;t!=0;w++){ t = t/10; } w--; cout<<(long)(temp2[i]/pow(10,w))<<"e"<<w+(5399-i)*9; break; } cout<<endl; cout<<x<<endl; x++; } } time(&time2); cout<<time2-time1; //GetSystemTime(&time1); cin>>o; return 0; } static long fib(long a[] ,long b[]){ long t; static long l=0; int s = 0; for (long i = l; i <= 5399; i++) { t = b[i]; b[i] = a[i]+b[i]; a[i] = t; } for (long i = 5399; i >= 0; i--) { b[i - 1] += (long)(b[i] / 1000000000L); b[i] = b[i] % 1000000000L; if(b[i]==0){ s++; if(s==5){ l = i; break; } } } return l; }问题主要还是在防止溢出上面。本身应该用java解决的问题,而且java中有biginteger使用要方便得多。但是效率太低,尤其tostring(),耗时太久。最后还是选择了C++。
相关文章推荐
- 洛谷 P1962 斐波那契数列
- C语言-斐波那契数列
- 斐波那契数列(Fibonacci sequence)Python实现的三种方案:列表 递归 生成器
- 【HDU - 4549 】M斐波那契数列 【矩阵快速幂+费马小定理降幂】
- 洛谷P1962 斐波那契数列
- python3 迭代器实现斐波那契数列
- 斐波那契数列-C语言实现
- C/C++经典程序训练2---斐波那契数列
- 洛谷 P2626 斐波那契数列(升级版)
- 剑指offer——斐波那契数列
- 【算法】斐波那契数列的计算方法
- Lintcode--3(366)--斐波那契数列
- 《剑指offer》--010--斐波那契数列
- 剑指Offer:斐波那契数列
- HDU 2041 超级楼梯(斐波那契数列)
- 三种java编程方法实现斐波那契数列
- 计蒜客 斐波那契数列 循环节 模拟
- 计蒜客-练习题 斐波那契数列
- Python 实现斐波那契数列
- (DP)斐波那契数列的动态规划求解(Fibonacci Dynamic Programming)