高精度怎么做???50分求助

P1255 数楼梯

chigiri_hyoma @ 2024-07-22 09:56:54

#include<bits/stdc++.h>
using namespace std;
long long a=1,b=1,x=0;
int n,i;
int main()
{
    int n;
    cin>>n;
    for(i=2;i<=n;i++){
        x=a+b;
        a=b;
        b=x;
    }
    cout<<x;
    return 0;
}

by tt12341234 @ 2024-07-22 10:03:42

@chigiri_hyoma 建议用py,不用考率高精度


by tt12341234 @ 2024-07-22 10:05:24

@chigiri_hyoma 代码:

n = int(input())
a=1
b=1
n-=1
if n > 0 :
    while n>0 :
        c=a+b
        a=b
        b=c
        n-=1
    print(b)
elif n == 0 :
        print(a)
else :
    a-=1
    print(a)
    #求关注

这样没re,我之前也问过这题


by tt12341234 @ 2024-07-22 10:05:54

@chigiri_hyoma 可以给个关注吗


by keep_shining @ 2024-07-22 10:07:31

@chigiri_hyoma 手写高精


by A_chicken_boy @ 2024-07-22 10:08:11

#include<bits/stdc++.h>

using namespace std;

int n,l=1;

int a[5010][5010];

void sc(int sb){

    for(int i=1;i<=l;i++){

        a[sb][i]=a[sb-1][i]+a[sb-2][i];

    }

    for(int i=1;i<=l;i++){

        if(a[sb][i]>9){

            a[sb][i+1]+=a[sb][i]/10;

            a[sb][i]%=10;

            if(a[sb][l+1]>0)l++;

        }

    }

}

int main(){

    scanf("%d",&n);

    a[1][1]=1;

    a[2][1]=2;

    for(int i=3;i<=n;i++){

    sc(i);

    }

    for(int i=l;i>=1;i--){

        printf("%d",a[n][i]);

    }

    return 0;

}

by chigiri_hyoma @ 2024-07-22 10:40:07

@tt12341234 已


|