高精度计算斐波那契数列

const int MAXN = 550;
const int MAXNLEN = 130;
int F[MAXN][MAXNLEN];
char Fi[MAXN][MAXNLEN],ans[MAXN];
void Fibo()
{
    F[1][0] = 1;
    F[2][0] = 2;
    for(int i = 3; i <= 500; ++i)
    {
        for(int j = 0; j <= 110; ++j)
        {
            F[i][j] = F[i][j] + F[i-1][j] + F[i-2][j];
            if(F[i][j] >= 10)
            {
                F[i][j+1] += F[i][j]/10;
                F[i][j] %= 10;
            }
        }
    }
    for(int i = 1; i <= 500; ++i)
    {
        int j;
        for(j = 110; j >= 0; j--)
            if(F[i][j] == 0)
                continue;
            else
                break;
        int k = 0;
        for(; j >= 0; j--)
            Fi[i][k++] = F[i][j] + '0';
        F[i][k] = '\0';
    }
}

你可能感兴趣的:(模板)