Advertisement
Guest User

Untitled

a guest
Jan 29th, 2017
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.53 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. class LastKNumbersSum
  5. {
  6.     static void Main()
  7.     {
  8.         long number = long.Parse(Console.ReadLine());
  9.         long steps = long.Parse(Console.ReadLine());
  10.    
  11.         long[] sequence = new long[number];
  12.    
  13.         sequence[0] = 1;
  14.        
  15.         for (long i = 1; i < number; i++)
  16.         {
  17.             long sum = 0, last = i-1, toSteps = 1;
  18.            
  19.             while (last >= 0 && toSteps <= steps)
  20.             {
  21.                 sum += sequence[last--];
  22.                 toSteps++;
  23.             }
  24.            
  25.             sequence[i] = sum;
  26.         }
  27.        
  28.         foreach (long value in sequence)
  29.             Console.Write(value + " ");
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement