1 solutions

  • 0
    @ 2025-11-5 19:42:18

    C++ :

    #include <iostream>
    using namespace std;
    
    int createfab(int m, int n)
    {
    	int i, j, lcount, *a = new int[n + 2];
    	for (i = 1; i <= n; i++)a[i] = i;
    	a[n + 1] = m + 1;
    	//for (j = 1; j < n; j++)printf("%d ", a[j]);
    	//printf("%d\n", a[n]);
    	lcount = 1;
    	while (a[1] < m - n + 1){
    		for (i = n; i>0; i--){
    			if (a[i] < a[i + 1] - 1){
    				a[i]++;
    				for (j = i; j < n; j++)a[j + 1] = a[j] + 1;
    				//for (j = 1; j < n; j++)printf("%d ", a[j]);
    				//printf("%d\n", a[n]);
    				lcount++;
    				break;
    			}
    		}
    	}
    	return lcount;
    }
    
    int main()
    {
    	int m, n;
    	while (cin >> m >> n)
    	{
    		cout << createfab(m, n) << endl;
    	}
    	return 0;
    }
    
    • 1

    Information

    ID
    19568
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By