递归算法是不可取的,因为效率很低,而且还有栈溢出的风险。
应该使用如下的迭代解法:
int Fibonacci(unsigned int n)
{
if(n <= 0)
{
return 0;
}
if(n == 1)
{
return 1;
}
int i = 0,j = 1,m;
unsigned int k;
for(k = 2; k <= ...
分类:
其他好文 时间:
2014-07-24 12:24:05
阅读次数:
233
Fibonacci Again!
时间限制:1000 ms | 内存限制:65535 KB
难度:2
描述
求第n个斐波那契数是否是一个素数,n为整数
f[n]=f[n-1]+f[n-2] (2
f[1]=3,f[2]=7
输入输入整数m,0
输出如果f[m]是素数 则输出Yes,否则输出No,
每行输出占一行。
样例输入
2
3
...
分类:
其他好文 时间:
2014-07-24 10:36:32
阅读次数:
272
题目描述:数学神童zouyu终于把0到100000000的Fibonacci数列 (f[0]=0,f[1]=1;f[i] = f[i-1]+f[i-2](i>=2))的值全部给背了下来。接下来,CodeStar...
分类:
其他好文 时间:
2014-07-23 12:05:06
阅读次数:
197
您可能听说过,带有 yield 的函数在 Python 中被称之为 generator(生成器),何谓 generator ? 我们先抛开 generator,以一个常见的编程题目来展示 yield 的概念。 如何生成斐波那契數列 斐波那契(Fibonacci)...
分类:
编程语言 时间:
2014-07-21 10:24:08
阅读次数:
281
Fibonacci Again
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 36028 Accepted Submission(s): 17385
Problem Description
There are an...
分类:
其他好文 时间:
2014-07-19 23:43:09
阅读次数:
391
Power of Fibonacci
Time Limit: 5 Seconds Memory Limit: 65536 KB
In mathematics, Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers of the following integer sequence...
分类:
其他好文 时间:
2014-07-19 11:48:45
阅读次数:
239
DZY Loves Fibonacci NumbersTime Limit:4000MSMemory Limit:262144KB64bit IO Format:%I64d & %I64uSubmitStatusAppoint description:DescriptionIn mathematic...
分类:
其他好文 时间:
2014-07-18 19:05:07
阅读次数:
305
聪哥推荐的题目区间修改和区间查询,但是此题新颖之处就在于他的区间修改不是个定值,而是从L 到 R 分别加 F1、F2、。。。Fr-l+1 (F为斐波那契数列)想了一下之后,觉得用fib的前缀和来解决,每次做懒惰标记记录下当前区间是从哪个L开始加起的,敲了一半之后发现有问题,就跟上次遇到的懒惰标记问题...
分类:
其他好文 时间:
2014-07-16 18:10:06
阅读次数:
270
In mathematical terms, the sequenceFnof Fibonacci numbers is defined by the recurrence relationF1?=?1;F2?=?1;Fn?=?Fn?-?1?+?Fn?-?2(n?>?2).DZY loves Fib...
分类:
其他好文 时间:
2014-07-16 16:45:19
阅读次数:
418
A delegate is a type that safely encapsulates a method, similar to a function pointer in C and C++. Unlike C function pointers, delegates are object-o...
分类:
其他好文 时间:
2014-07-16 15:43:31
阅读次数:
228