无符号长隆会不会超越93th Fibonacci数? [英] Unsigned Long Long Won't Go Beyond The 93th Fibonacci Number?

查看:100
本文介绍了无符号长隆会不会超越93th Fibonacci数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的code我写了寻找第n个斐波纳契数:

Here's the code I wrote for finding the n-th Fibonacci number:

unsigned long long fib(int n)
{
    unsigned long long u = 1, v = 1, t;

    for(int i=2; i<=n; i++)
    {
        t = u + v;
        u = v;
        v = t;
    }

    return v;
}

虽然算法运行速度很快pretty的,输出开始发飙了当n> 93。我觉得/知道这是因为无符号长长的64位大小。我是新来的C ++,但逛逛这个,所以我可以得到类似FIB(9999)?

While the algorithm runs pretty quickly, the output starts to freak out when n>93. I think/know it's because of the unsigned long long's 64bit size. I'm new to C++ but are there ways of getting around this so I can get the answer of something like fib(9999)?

感谢

推荐答案

http://gmplib.org/

这篇关于无符号长隆会不会超越93th Fibonacci数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆