10 solutions

  • 3
    @ 2023-9-21 15:27:26

    #include<stdio.h>

    int main() {

    int n,a[10000007];

    scanf("%d",&n);

    a[1]=1,a[2]=1;

    if(n= =1 || n= =2){printf("1");}

    else {

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

    {

    a[i]=a[i-1]%10007+a[i-2]%10007;

    }

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

    }

    return 0;

    }

    • 2
      @ 2022-1-26 20:44:41
      #include<stdio.h>
      int main(){
      int f1=1,f2=1;
      int fn;
      int sum = 0;
      scanf("%d",&fn);
      if(fn<3){
      printf("1");
      }
      else{
      for(int i=3; i<=fn; i++){
      sum = (f1+f2)%10007;
      f1 = f2;
      f2 = sum;
      }
      printf("%d",sum);
      }
      return 0;
      }
      
      • 1
        @ 2024-11-30 11:11:00

        unsigned long long fi[10000000]一定得是全局变量,要不然会爆

        #include <bits/stdc++.h>
        using namespace std;
        unsigned long long  fi[10000000];
        int main()
        {
        	fi[2]=fi[1]=1;
        	int n;
        	cin>>n;
        	for(int i=3;i<=n;i++)
        	{
        		fi[i]=(fi[i-1]+fi[i-2])%10007;
        	}
        	cout<<fi[n];
        }
        
        • 1
          @ 2024-5-12 20:43:33
          (新手,基本知识全忘了,开始凭感觉写)
          查了一下好像不能直接用变量定义a[n] 
          但不知道为什么这么写,也没出错,全过了...
          
          定义的时候,把数组中的n改成一个较大的值如100000,也可以全过
          ---
          
          #include<bits/stdc++.h>
          #include<cmath>
          using namespace std;
          
          int main(){
          	int n;
          	cin>>n;
          	int a[n];
          	a[0]=1;a[1]=1;
          	for(int i=2;i<n;i++){
          		a[i]=a[i-1]%10007+a[i-2]%10007;
          	}
          	cout<<a[n-1]%10007;
          	return 0;
          }
          
          • 1
            @ 2022-4-4 17:15:53

            C++

            用递推写了一个,怕超时

            #include <iostream>
            using namespace std;
            int main()
            {
                int d1=1,d2=1,d3;
                int n = 0;
                cin >> n;
                int i = 2;
                if(n <= 2)  cout << d1 << endl;
                else
                {
                    while(i < n)
                    {
                        d3 = (d1+d2)%10007;
                        d1 = d2;
                        d2 = d3; 
                        i++;
                    }
                    cout << d3 << endl;
                }
                return 0;
            }
            
            • 0
              @ 2024-10-23 14:44:12

              #include<stdio.h> int main() { int x, y; int num[20]; num[0] = 1; num[1] = 1; scanf_s("%d",&x); for (y=1;y<=x;y++) { num[y + 1] = num[y - 1] + num[y];

              }
              printf("%d",num[x-1]);
              return 0;
              

              }

              • 0
                @ 2024-10-23 14:43:38

                #include<stdio.h> int main() { int x, y; int num[20]; num[0] = 1; num[1] = 1; scanf_s("%d",&x); for (y=1;y<=x;y++) { num[y + 1] = num[y - 1] + num[y];

                }
                printf("%d",num[x-1]);
                return 0;
                

                }

                • 0
                  @ 2023-12-18 17:26:20

                  #include<stdio.h> int fb(int x) { int t,t1=1,t2=1; if(x1) return 1; else if(x2) return 1; else { for(int i=2;i<x;i++) { t=(t1+t2)%10007; t1=t2; t2=t; } return t; } } int main() { long long m; scanf("%d",&m); printf("%d",fb(m)); return 0; }

                  • 0
                    @ 2023-10-25 21:23:23
                    #include <stdio.h>
                    #pragma warning (disable:4996)
                    
                    int main() {
                        int n;
                        scanf("%d", &n);
                        long long a = 0, b = 1, c;
                        for (int i = 2; i <= n; i++) 
                        {
                            c = (a + b) % 10007;
                            a = b;
                            b = c;
                        }
                        printf("%lld", b);
                            return 0;
                    }
                    
                    
                    • 0
                      @ 2022-3-7 19:58:37
                      #include <stdio.h>
                      #include <algorithm>
                      #include <math.h>
                      #include <vector>
                      using namespace std;
                      vector<int> a;
                      int main() {
                          int n,i=1;
                          a.push_back(1);
                          a.push_back(1);
                          scanf("%d",&n);
                          if(n==1||n==2)
                          {
                              printf("1\n");
                              return 0;
                          }
                          for(int i=2;i<n;i++)
                          {
                              int tmp=(a[i-1]%10007+a[i-2]%10007)%10007;
                              a.push_back(tmp);
                          }
                          printf("%d\n",a[n-1]);
                          return 0;
                      }
                      
                      • 1

                      Information

                      ID
                      38
                      Time
                      1000ms
                      Memory
                      256MiB
                      Difficulty
                      8
                      Tags
                      # Submissions
                      2327
                      Accepted
                      309
                      Uploaded By