Sphere Online Judge

SPOJ Problem Set (classical)

78. Marbles

Problem code: MARBLES

Hänschen 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. Hänschen 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 possibilites 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 Hänschen 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 Hänschen 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

Added by:Adrian Kuegel
Date:2004-06-19
Time limit:1s
Source limit:10000B
Memory limit:256MB
Cluster: Pyramid (Intel Pentium III 733 MHz)
Languages:All except: NODEJS PERL 6
Resource:own problem

hide comments
2013-04-24 01:54:19 Eduardo Nunes
simple nck, no need to worry about the constraints of the input(1<=k<=n<=1000000) because the answer will always fit a signed 64 bit integer :-D
2013-03-31 15:21:43 Harsha
in python we always get time limit exceeded
--ans(francky)--> Check rank list in Python, ...

Last edit: 2013-03-31 16:29:19
2013-03-09 12:10:33 Lakshman
c++ got AC while same thing in JAVA giving WA don't know why..
2013-02-05 17:34:34 error
easy one...
2013-01-22 18:48:24 guy fawkes
god bless BigInt
2012-11-14 19:48:34 TLE
gives out time limit exceeded when directly using the formula for calculating the number of ways..also time limit is breached when multiplying individual terms in the simplified expression from the nck term...any hints??
2012-09-28 14:14:52 hemalatha
java...i love u...
2012-09-10 17:06:23 #FANOFACrush#
nyce one :) nck :)
2012-09-10 17:06:23 #FANOFACrush#


Last edit: 2012-09-10 17:06:41
SPOJ © 2013 Sphere Research Labs. All Rights Reserved.