Interesting Stirling Task
题号:NC209773
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

The Stirling numbers of the first kind are defined such that the number of permutations of  elements which contain exactly  permutation cycles (with cycles in opposite directions counted as distinct). The well known recurrence relation is defined as follows:

for ,with the initial conditions

for .
Roundgod is now solving an interesting task, which gives four integers and , and asks the value of

where  is prime. Seems Roundgod comes up with the main idea in only one minute. Can you be faster?

输入描述:

The only line contains four integers and   is prime.

输出描述:

Output an integer denoting the answer.
示例1

输入

复制
4 1 4 5

输出

复制
4
示例2

输入

复制
6 5 5 29

输出

复制
15