304 North Cardinal St.
Dorchester Center, MA 02124

# Marbles CodeChef Solution

## Problem – Marbles CodeChef Solution

Rohit dreams he is in a shop with an infinite amount of marbles. He is allowed to select n marbles. There are marbles of k different colors. From each color there are also infinitely many marbles. Rohit wants to have at least one marble of each color, but still there are a lot of possibilities for his selection. In his effort to make a decision he wakes up. Now he asks you how many possibilities for his selection he would have had. Assume that marbles of equal color can’t be distinguished, and the order of the marbles is irrelevant.

### Input

The first line of input contains a number T <= 100 that indicates the number of test cases to follow. Each test case consists of one line containing n and k, where n is the number of marbles Rohit selects and k is the number of different colors of the marbles. You can assume that 1<=k<=n<=1000000.

### Output

For each test case print the number of possibilities that Rohit would have had. You can assume that this number fits into a signed 64 bit integer.

### Example

``````Input:
2
10 10
30 7
Output:
1
475020
``````

## Marbles CodeChef Solution in C++17

``````#include <iostream>
using namespace std;

int main() {
long long testCases;
cin >> testCases;
while(testCases--) {
long long n,k;
cin >> n >> k;
if(n==k) {
cout << 1 << endl;
}
else {
long long diff = n-k;
long long possibility = 1;
for(int i=1;i<k;i++) {
possibility = possibility*(diff+i)/i;
}
cout << possibility << endl;
}
}
return 0;
}
``````

## Marbles CodeChef Solution in Pyth 3

``````# cook your dish here
from math import comb

if __name__ == "__main__":
t = int(input())
for _ in range(0,t):
n,k = map(int,input().split())
print(comb(n-1,k-1))
``````

## Marbles CodeChef Solution in Java

``````/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int k=sc.nextInt();
long as=1;
for(int i=1;i<k;i++){
as=as*(n-k+i)/i;
}
System.out.println(as);
}
}
}
``````
##### Marbles CodeChef Solution Review:

In our experience, we suggest you solve this Marbles CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Marbles CodeChef Solution

Find on CodeChef

##### Conclusion:

I hope this Marbles CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions