Simeon1995

Untitled

Oct 6th, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Last_K_Numbers_Sums_Sequence
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. long n = long.Parse(Console.ReadLine());
  14. long k = long.Parse(Console.ReadLine());
  15. long[] array = new long[n];
  16. array[0] = 1;
  17. for (long i = 0; i < array.Length; i++)
  18. {
  19. for (long j = i - k; j < i; j++)
  20. {
  21. try
  22. {
  23. array[i] = array[i] + array[j];
  24. }
  25. catch(IndexOutOfRangeException)
  26. { }
  27. }
  28. Console.WriteLine(array[i]);
  29. }
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment