kirililchev3

Last K Num Sums Sequence

Jun 3rd, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. namespace Last_K_Numbers_Sums
  2. {
  3.     using System;
  4.  
  5.     public class Last_K_Numbers_Sums
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             int k = int.Parse(Console.ReadLine());
  11.             long[] array = new long[n];
  12.             array[0] = 1;
  13.             for (int i = 1; i < array.Length; i++)
  14.             {
  15.                 long sum = 0L;
  16.                 if (i < k)
  17.                 {
  18.                     for (int j = 0; j < array.Length; j++)
  19.                     {
  20.                         sum += array[j];
  21.                     }
  22.                 }
  23.                 else
  24.                 {
  25.                     for (int j = i - k; j < array.Length; j++)
  26.                     {
  27.                         sum += array[j];
  28.                     }
  29.                 }
  30.  
  31.                 array[i] = sum;
  32.             }
  33.  
  34.             for (int i = 0; i < array.Length; i++)
  35.             {
  36.                 Console.Write("{0} ", array[i]);
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment