VelizarAvramov

03. Last K Numbers Sums

Nov 25th, 2018
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _03._Last_K_Numbers_Sums
  4. {
  5.     class LastKNumbersSums
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int lenght = int.Parse(Console.ReadLine());
  10.             int count = int.Parse(Console.ReadLine());
  11.  
  12.             long[] sequence = new long[lenght];
  13.             sequence[0] = 1;
  14.  
  15.             for (int i = 1; i < lenght; i++)
  16.             {
  17.                 long sum = 0;
  18.                 int counter = 0;
  19.                 for (int j = i; j >= 0; j--)
  20.                 {
  21.                     sum += sequence[j];
  22.                     counter++;
  23.                     if (counter > count)
  24.                     {
  25.                         break;
  26.                     }
  27.                 }
  28.                 sequence[i] = sum;
  29.             }
  30.             Console.WriteLine(string.Join(" ", sequence));
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment