3 solutions

  • 2
    @ 2025-11-19 17:58:23

    金画99 闪酒金婚 π头99(朱包坠喜欢的CP) 同意点好评 (wy医✔太赖了)

    • 1
      @ 2025-11-19 17:44:07

      #include using namespace std;

      int main() { int n; cin >> n; // 输入要查询的项数 n

      // 处理前两项的特殊情况
      if (n == 1) {
          cout << 0 << endl;
          return 0;
      }
      if (n == 2) {
          cout << 1 << endl;
          return 0;
      }
      
      // 初始化前两项
      int a = 0;  // 第 1 项
      int b = 1;  // 第 2 项
      int result;  // 存储第 n 项的结果
      
      // 从第 3 项开始循环计算,直到第 n 项
      for (int i = 3; i <= n; ++i) {
          result = a + b;  // 当前项 = 前两项之和
          a = b;           // 更新前两项:将 b 移到 a 的位置
          b = result;      // 将当前结果移到 b 的位置
      }
      
      cout << result << endl;  // 输出第 n 项
      return 0;
      

      }

      • -3
        @ 2025-11-19 17:48:12

        嘻嘻嘻

        • 1

        Information

        ID
        1037
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        7
        Tags
        # Submissions
        15
        Accepted
        10
        Uploaded By