All submissions for this problem are available.
Chef recently visited a strange land with strange currency. One day Chef needed to make change to pay for an item with coins, and wondered how many ways it could be done, assuming an infinite supply of each type of coins. Two ways are considered different if there is some coin that appears a different number of times in each sum. The answer may be very large, so Chef only needs to know the remainder when the answer is divided by 1000000007 (109 + 7).
Chef noticed something curious about the currency in question: not only do all coins have different denominations, but no two denominations of coin share any common factor other than 1.
The first line of the input contains an integer T, denoting the number of test cases. The description of T test cases follows. The first line of each test case contains two space-separated integers N and C, denoting the number of different coin types and the desired total coinage, respectively. The second line contains N space-separated integers D1, D2, ..., DN, denoting the denominations of the coins.
For each test case, output on a separate line the number of ways to make the desired amount of change, modulo 1000000007.
- 1 ≤ T ≤ 5
- 1 ≤ N ≤ 50
- 1 ≤ C ≤ 10100
- 1 ≤ Di ≤ 500
- All Di are pairwise distinct and pairwise relatively prime.
Input: 3 3 16 3 4 5 2 2000000014 1 2 3 380134 23 5 2 Output: 4 1 314159265
Example case 1. There are 4 ways to make a total of 16 using coins with values 3, 4 and 5:
- 16 = 4 + 4 + 4 + 4
- 16 = 3 + 4 + 4 + 5
- 16 = 3 + 3 + 5 + 5
- 16 = 3 + 3 + 3 + 3 + 4
Example case 2. There are 1000000008 ways to make the desired change. The remainder when divided by 1000000007 is 1.
|Tags||advanced-math, hard, march13, maths, pieguy|
|Time Limit:||3 sec|
|Source Limit:||50000 Bytes|
|Languages:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.5, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.