Advertisement
Guest User

Last K Numbers Sums

a guest
Oct 19th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 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 ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int a = int.Parse(Console.ReadLine());
  14.             int b = int.Parse(Console.ReadLine());
  15.             int[] array = new int[a*a];
  16.             int sum = 0;
  17.             int cnt = 0;
  18.             array[0] = 1;
  19.             if (a==1)
  20.             {
  21.                 Console.WriteLine(1);
  22.             }
  23.             else
  24.             {
  25.                 for (int i = 1; i < a; i++)
  26.                 {
  27.                     sum = 0;
  28.  
  29.                     for (int j = 0; j < i; j++)
  30.                     {
  31.                         sum += array[j];
  32.                     }
  33.                     array[i] = sum;
  34.                 }
  35.                 for (int i = b; i <= a; i++)
  36.                 {
  37.                     sum = 0;
  38.  
  39.                     for (int j = i - 1; j >= cnt; j--)
  40.                     {
  41.                         sum += array[j];
  42.                     }
  43.                     cnt++;
  44.                     array[i] = sum;
  45.                 }
  46.                 for (int n = 0; n < a; n++)
  47.                 {
  48.                     Console.Write(array[n] + " ");
  49.                 }
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement