3 solutions

  • 5
    @ 2024-11-17 20:44:10

    咱可以用递归做图省事

    代码:

    #include <bits/stdc++.h>
    typedef long long ll;
    using namespace std;
    const int N=10010;
    int n;
    ll f(int n){
        if(n==1||n==2){
        	return 1;
    	}
        return f(n-1)+f(n-2);
    }
    int main() {
    	
    	cin.sync_with_stdio(false);
    	ios::sync_with_stdio(0);	
        cin>>n;
        cout<<f(n)<<".00"<<'\n';//起码给题目一点脸
        
        return 0;
    }
    
    • 4
      @ 2024-11-3 11:30:59
      #include<bits/stdc++.h>
      using namespace std;
      int main(){
          double n,f;cin>>n;
          f=1.0*(pow((1+sqrt(5))/2,n)-pow((1-sqrt(5))/2,n));
          printf("%.2lf",f/sqrt(5));
          return 0;
      }//按公式来的
      
      • 4
        @ 2024-10-29 17:17:54
        #include<iostream>
        using namespace std;
        long long a=1,b=1,c=0;
        int n,i;
        int main()
        {
            cin>>n;
            for (i=3;i<=n;i++)
            {
                c=a+b;
                a=b;
                b=c;
            }
            cout<<c<<".00";///
            return 0;
        }
        
        
        
        • 1

        [习4.4]月落乌啼算钱(斐波那契数列)

        Information

        ID
        418
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        2
        Tags
        (None)
        # Submissions
        59
        Accepted
        37
        Uploaded By