50分的代码,求大佬帮忙改一下?

P1255 数楼梯

fjitro @ 2023-06-07 22:57:51

#include<bits/stdc++.h>
using namespace std;
int Fi(unsigned long long n){
    if(n==2)return 2;
    if(n==1)return 1;
    else return Fi(n-1)+Fi(n-2);
}
int main(){
    unsigned long long a;
    cin>>a;
    unsigned long long m=Fi(a);
    cout<<m;
}

by elbissoPtImaerD @ 2023-06-07 22:59:42

@yanglangming2012 答案超出了 unsigned long long 类型的储存范围,俗称“爆 long long 了”,需要写高精度


by fjitro @ 2023-06-07 23:00:33

谢谢dalao


by fjitro @ 2023-06-07 23:01:52

那问一下怎么处理呢??


by elbissoPtImaerD @ 2023-06-07 23:07:49

@yanglangming2012 在这里学习高精度:https://oi-wiki.org/math/bignum/


by Chtholly_is_cute @ 2023-06-08 06:24:34

@yanglangming2012

0.需要开高精度\ 1.递归会超时


by SCAR_L @ 2023-06-08 07:38:52

@yanglangming2012

  1. 加高精度:https://www.luogu.com.cn/blog/Jiangyuchen-2010/Z4-22

  2. 加记忆化


|