Back
Close

X-Fibonacci

Statement

 Goal

Generate a sequence of T non-zero terms using the function defined below.

X-Fibonacci is a custom function defined as
F(n>1) = F(n-1) + F(n-2) + ... + F(n-X);
 F(1) = 1;
 F(n<1) = 0

Where n is in integer.


Consequently, 2-Fibonacci is defined as
F(n>1) = F(n-1) + F(n-2)
The first 6 non-zero terms are 1 1 2 3 5 8

And following, 3-Fibonacci is defined as
F(n>1) = F(n-1) + F(n-2) + F(n-3)
The first 6 non-zero terms are 1 1 2 4 7 13
Input
Line 1: X Fibonacci, number of recursive terms
Line 2: T terms to output
Output
The first T non-zero terms of the X-Fibonacci sequence separated by a space.
Constraints
2 ≤ X ≤ 16
6 ≤ T ≤ 31
Example
Input
2
6
Output
1 1 2 3 5 8

Game modes
Fastest, Shortest

Test cases
Standard Fibonacci Test
Input
2 6
Output
1 1 2 3 5 8

Validator 1 Validator
Input
2 7
Output
1 1 2 3 5 8 13

3-Fibonacci Test
Input
3 6
Output
1 1 2 4 7 13

Validator 2 Validator
Input
3 25
Output
1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136 5768 10609 19513 35890 66012 121415 223317 410744 755476 1389537

X-Fibonacci Test
Input
5 10
Output
1 1 2 4 8 16 31 61 120 236

Validator 3 Validator
Input
5 30
Output
1 1 2 4 8 16 31 61 120 236 464 912 1793 3525 6930 13624 26784 52656 103519 203513 400096 786568 1546352 3040048 5976577 11749641 23099186 45411804 89277256 175514464

Y-Fibonacci Test
Input
6 8
Output
1 1 2 4 8 16 32 63

Validator 4 Validator
Input
6 16
Output
1 1 2 4 8 16 32 63 125 248 492 976 1936 3840 7617 15109

Fibonacci**2 Test
Input
16 10
Output
1 1 2 4 8 16 32 64 128 256

Validator 5 Validator
Input
15 8
Output
1 1 2 4 8 16 32 64

Z-Fibonacci Test
Input
9 13
Output
1 1 2 4 8 16 32 64 128 256 511 1021 2040

Validator 6 Validator
Input
7 12
Output
1 1 2 4 8 16 32 64 127 253 504 1004

Test 7 Test
Input
13 15
Output
1 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8191

Validator 7 Validator
Input
16 31
Output
1 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65535 131069 262136 524268 1048528 2097040 4194048 8388032 16775936 33551616 67102720 134204416 268406784 536809472

Solution language

Solution

Stub generator input