Adarsh and Numbers
Adarsh is trying to express a given positive number as a sum of several numbers in different ways. He is astounded by the number of ways in which it could be done. So, he decided to develop a program for doing the same. Given a number N and a positive integer X, help Adarsh to find the number of ways in which N could be expressed as sum of X whole numbers. In simple words you are given X whole numbers -x1,x2,x3….xn. You have to find the number of integral solutions of x1+x2+x3+…+xn=N. Note that xi ≥ 0.
The first line of input contains T, number of test cases. The following T lines contain two space separated integers N and X.
For each test case, print a single line denoting number of ways in which N can be expressed as sum of X numbers.
- 1 ≤ T ≤ 50
- 1 ≤ N ≤ 40
- 1 ≤ X ≤ 20
Input: 2 3 2 5 2 Output: 4 6
Example case 1: 3 can be expressed in the following 4 ways as sum of 2 numbers : 2+1, 1+2, 3+0, 0+3
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions