QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 10

#11845. Subsets [A]

統計

We are going to consider subsets $ P $ of a given set $\{1, \ldots, n\}$. We are interested in subsets such that for a given natural number $ x > 1 $ and for any natural number $ y $ at least one of the numbers $ y $, $ x \cdot y $ doesn't belong to $ P $. We would like to calculate the number of such subsets, that have exactly $ k $ elements. It is possible that the number of such subsets is huge - therefore it is sufficient to calculate the remainder of the division of the result by $ m $.

Write a program which:

  • reads from the standard input four integers: $ n $, $ m $, $ k $ and $ x $,
  • calculates the remainder of the division by $ m $ of the number of $ k $-element subsets of set $\{1, \ldots, n\}$, that fulfill the requirements described above,
  • writes result to the standard output.

Input Format

In the first and only line of the standard input there are four integers $ n $, $ m $, $ k $ and $ x $ ($1 ≤ n ≤ 10^{18}$, $2 ≤ m ≤ 1\,000\,000$, $0 ≤ k ≤ 1\,000$, $2 ≤ x ≤ 10$), separated by single spaces.

Output Format

The first and only line should contain one integer - the reminder of the division by $ m $ of the number of $ k $-element subsets of set $\{1, \ldots, n\}$ that fulfill the specified requirements.

Example

Input

6 1234 3 2

Output

9

Notes

Considered subsets are: {1, 3, 4}, {1, 3, 5}, {1, 4, 5}, {1, 4, 6}, {1, 5, 6}, {2, 3, 5}, {2, 5, 6}, {3, 4, 5} and {4, 5, 6}.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.