#include <iostream>  
#include <cstdio>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main()
{
    int a[120];
    int k, m;
    while (1)
    {
        cout << "输入阶数k和约定的常数max。k和max用空格分开。" << endl;
        cin >> k >> m;
        int i;
        for (i = 0; i < k - 1; i++)
            a[i] = 0;
        a[k - 1] = 1;
        a[k] = 1;
        int n = k + 1;
        if (m == 0)
        {
            cout << k - 2 << endl;
            cout << 1 << endl;
            return 0;
        }
        if (m == 1)
        {
            cout << k << endl;
            cout << 1 << endl;
            return 0;
        }
        while (a[n - 1] <= m)
        {
            a[n] = 2 * a[n - 1] - a[n - k - 1];
            n++;
        }
        cout << n - 2 << endl;
        cout << a[n - 2] << endl;
    }
    
    return 0;
}
View Code

相关文章:

  • 2021-12-05
  • 2021-12-06
  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
  • 2019-10-11
  • 2022-12-23
  • 2021-11-02
猜你喜欢
  • 2021-12-21
  • 2022-01-18
  • 2021-05-30
  • 2021-04-25
  • 2022-12-23
相关资源
相似解决方案