wa*4

P1255 数楼梯

hkr1469 @ 2022-08-23 17:51:11


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

by hkr1469 @ 2022-08-23 17:52:48

!(好像要高精度)


by Sad_Rex @ 2022-08-23 18:15:03

@hkr1469

Python

a = int(input())
if a == 1:
    print(1)
else:
    b = 1
    c = 1
    for i in range(1,a):
        d = b + c
        b = c
        c = d
    print(d)

|