斐波纳契数 [英] Fibonacci numbers
问题描述
您好,我有一个小问题,我正在尝试编写一个程序,
将计算Fibonacci数字系列,我有代码
完成一个问题。我用了很长的时间来存储数字,当数字太大时我用了b $ b来最大化int并且我不能算得更高。我试图使用极大的数字,我想
使用最多10 ^ 50左右。所以我的问题是我该怎么做?我只是学习语言,而且我无法想到任何变量
存储限制。我很感激任何建议。
Lee ;-)
Hello, I have a small problem, I am trying to write a program that
will calculate the Fibonacci number series, and I have the code
complete with one problem. I used a long in to store the numbers, and
when the numbers get too large it maxes out the int and I can''t count
any higher. I am trying to use extremely large numbers, I would like
to use up to 10^50 or so. So my question is how do I do this? I''m just
learning the language and I can''t think of any way around variable
storage limitations. I would appreciate any advice.
Lee ;-)
推荐答案
你必须为此编写自己的类,超额算术
运算符,特别是你的情况下的+。
当然还有如何存储号码的问题。其中一种方法是将它存储为字符串。它可能不是内存和速度方面最有效的方式,但确实可以直接实现
。初始化也很干净,只需写:
巨大(123456789);
另一种方法是使用多个整数(或多头)存储数字。
你可能比字符串更有效地实现它,但是我认为它会让代码变得更复杂。
hth,
Joost
You will have to write your own class for that and overload the arithmic
operators, especially the + in your case.
Of course there is the question of how to store the number. One way to do
it, is to store it as a string. It might not be the most efficient way in
terms of memory and speed, but it does make the implementation
straight-forward. Initialization is also clean, just write:
Huge("123456789");
Another way to do it is to use multiple ints (or longs) to store the number.
You could probably implement this more efficiently than with strings, but I
think it makes the code a bit more complicated.
hth,
Joost
dl ****** @ cc.usu.edu 写道:
你好,我有一个小问题,我正在尝试写一个程序
将计算Fibonacci数字序列,并且我的代码
完成了一个问题。我用了很长时间来存储数字,而当数字变得过大时,它最大限度地提高了数字,我无法计算更高的数字。我试图使用极大的数字,我想使用最多10 ^ 50左右。所以我的问题是我该怎么做?我只是在学习语言,我无法想到任何可变的存储限制。我很感激任何建议。
Lee; - )
Hello, I have a small problem, I am trying to write a program that
will calculate the Fibonacci number series, and I have the code
complete with one problem. I used a long in to store the numbers, and
when the numbers get too large it maxes out the int and I can''t count
any higher. I am trying to use extremely large numbers, I would like
to use up to 10^50 or so. So my question is how do I do this? I''m just
learning the language and I can''t think of any way around variable
storage limitations. I would appreciate any advice.
Lee ;-)
使用双倍可能是最简单的,因为你得到52位的准确度。
否则可能是__in64。
Ryan
use a double is probably the easiest as you get 52 bits of accuracy.
Otherwise maybe an __in64.
Ryan
Ryan Winter写道:
Ryan Winter wrote:
使用double可能是最简单的,因为你得到52位的准确度。
否则可能是__in64。
use a double is probably the easiest as you get 52 bits of accuracy.
Otherwise maybe an __in64.
__int64:)
__int64 :)
这篇关于斐波纳契数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!