All Tracks Math Number Theory Problem

Binomial Coefficient
Tag(s):

Combinatorics, Math, Medium

Problem
Editorial
Analytics

Our hero - Maga has been working on a research related to Pascal’s Triangle for about a month. He has recently found a new problematic thing for his research. He has to calculate a big number. But he is very busy. Could you do it for him?

You are given a binomial as this: (a * x + b * y)^n. You have to find the binomial coefficient of x^k * y^(n-k) modulo 10^9+7.

Input:

You are given 4 integers: each space separated integers a, b, n and k.

Output:

Output 1 integer: the binomial coefficient of x^k * y^(n-k) mod (10^9+7).

Constraints:

1 <= a, b <= 100

1 <= n <= 10^6

1 <= k <= min(n,10^5)

SAMPLE INPUT
1 1 4 2
SAMPLE OUTPUT
6
Explanation

The result is 6. In the (x+y)^4 binomial, the coefficient of x^2 * y^2 is 6.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 64 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

Women Techmakers Code Jam with GDG New Delhi

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications