QOJ.ac

QOJ

Time Limit: 0.5 s Memory Limit: 128 MB Total points: 100

#14479. 数列

الإحصائيات

小 T 最近在学着买股票,他得到内部消息:F 公司的股票将会疯涨。

股票每天的价格已知是正整数,并且由于客观上的原因,最多只能为 $N$。在疯涨的 $K$ 天中小 T 观察到:除第一天外每天的股价都比前一天高,且高出的价格(即当天的股价与前一天的股价之差)不会超过 $M$,$M$ 为正整数。并且这些参数满足 $M(K-1) < N$。

小 T 忘记了这 $K$ 天每天的具体股价了,他现在想知道这 $K$ 天的股价有多少种可能。

输入格式

输入文件只有一行用空格隔开的四个数:$N$、$K$、$M$、$P$。对 $P$ 的说明参见后面“输出格式”中对 $P$ 的解释。

输出格式

仅包含一个数,表示这 $K$ 天的股价的可能种数对于 $P$ 的模值。

样例数据

样例输入

7 3 2 997

样例输出

16

样例解释

输出样例的16表示输入样例的股价有16种可能:

  • {1,2,3},{1,2,4},{1,3,4},{1,3,5},
  • {2,3,4},{2,3,5},{2,4,5},{2,4,6},
  • {3,4,5},{3,4,6},{3,5,6},{3,5,7},
  • {4,5,6},{4,5,7},{4,6,7},{5,6,7}。

子任务

输入保证 $20\%$ 的数据 $M,N,K,P \le 20000$,保证 $100\%$ 的数据 $M,K,P \le 10^9$,$N \le 10^{18}$。

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.