Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _03._Last_K_Numbers_Sums
- {
- class LastKNumbersSums
- {
- static void Main(string[] args)
- {
- int lenght = int.Parse(Console.ReadLine());
- int count = int.Parse(Console.ReadLine());
- long[] sequence = new long[lenght];
- sequence[0] = 1;
- for (int i = 1; i < lenght; i++)
- {
- long sum = 0;
- int counter = 0;
- for (int j = i; j >= 0; j--)
- {
- sum += sequence[j];
- counter++;
- if (counter > count)
- {
- break;
- }
- }
- sequence[i] = sum;
- }
- Console.WriteLine(string.Join(" ", sequence));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment