QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 100

#4867. 太简单了!

Statistiques

序列 $S_n$ 定义如下:

$$S_n = \left\lceil (a + \sqrt{b})^n \right\rceil \pmod m$$

其中 $a, b, n, m$ 为正整数。$\lceil x \rceil$ 表示 $x$ 的向上取整。例如 $\lceil 3.14 \rceil = 4$。你需要计算 $S_n$。 作为一名顶尖程序员,你会说:太简单了!

输入格式

包含多组测试数据,每组测试数据占一行,包含四个正整数:$a, b, n, m$。其中 $0 < a, m < 2^{15}$,$(a-1)^2 < b < a^2$,$0 < b, n < 2^{31}$。 输入以文件结束符(EOF)结束。

输出格式

对于每组测试数据,输出一个整数 $S_n$。

样例

输入格式 1

2 3 1 2013
2 3 2 2013
2 2 1 2013

输出格式 1

4
14
4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.