Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class LastKNumbersSum
- {
- static void Main()
- {
- long number = long.Parse(Console.ReadLine());
- long steps = long.Parse(Console.ReadLine());
- long[] sequence = new long[number];
- sequence[0] = 1;
- for (long i = 1; i < number; i++)
- {
- long sum = 0, last = i-1, toSteps = 1;
- while (last >= 0 && toSteps <= steps)
- {
- sum += sequence[last--];
- toSteps++;
- }
- sequence[i] = sum;
- }
- foreach (long value in sequence)
- Console.Write(value + " ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement