Advertisement
Guest User

Untitled

a guest
May 29th, 2016
1,370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 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 _02LastKNumberSum
  8. {
  9. class LastKNumberSum
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14. int k = int.Parse(Console.ReadLine());
  15. long[] arr = new long[n];
  16. arr[0] = 1;
  17. for (int current = 1; current < arr.Length; current++)
  18. {
  19. int start = Math.Max(0, current - k);
  20. int end = current - 1;
  21. long sum = 0;
  22. for (int prev = start; prev <= end; prev++)
  23. {
  24. sum += arr[prev];
  25. }
  26. arr[current] = sum;
  27. }
  28. for (int i = 0; i < arr.Length; i++)
  29. {
  30. Console.WriteLine(arr[i] + " ");
  31. }
  32. Console.WriteLine();
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement