What will be the value of k in given pseudo code?

http://gateoverflow.in/?qa=blob&qa_blobid=14775353093279358576

I'm unable to understand how the value of K, is equivalent to selecting m integers with repetition allowed, out of n integers (1,2,3,...,n). Kindly explain in detail, preferably visual detail.

1Comment
Sumit Verma @sumitkgp
25 May 2017 03:59 pm

Taking m=2,
k=0;
for i1 = 1 to n 
 for i2 =1 to i1
  k=k+1

for i=1, k is incrementing  1 time
for i=2, k is incrementing 2 times
for i=3, k is incrementing  3 times
........................................................
for i=n, k is incrementing n times.
Total increment in k = 1+2+3+................+n = n(n+1)/2 = selecting 2 integers with repetition among n integers.
Taking m=3,
for i=1, k is incrementing 1 time. (1 times)
for i=2, k is incrementing 3 times. (1+2 times)
for i=3, k is incrementing 5 times. (1+2+3 times)
.........................................................................
for i=n, k is incrementing (1+2+3+....n) times.
Total increment in k = 1 + (1+2) + (1+2+3) + (1+2+3+4) +.............(1+2+3......+n)
 = n(n+1)(n+2) / 6  =  selecting 3 integers with repetition among n integers.
Similarly, Take m=k, K will be C(n+k-1,k) =  selecting m integers with repetition among n integers.