当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3777:Snail Alice

题目描述
Snail Alice is a snail indulged in math. One day, when she was walking on the grass, suddenly an accident happened. Snail Alice fell into a bottomless hole, which was deep enough that she kept falling for a very long time. In the end, she caught the lateral wall of the hole and stop falling down. She named the place where she stopped “lucky place” immediately.

Snail Alice decided to climb up along the wall from the “lucky place”. The first day she climbed up q0 (q is a positive constant integer) metres, but at night when she fell asleep, she fell down q1 metres. She was shocked when she woke up, and she decided to make an extra effort. The second day she finally climbed up q2 metres. To her surprise, she fell down faster because of the tiredness. She fell down q3 metres at night. The longer she climbed up the longer she fell down. But finally, she still climbed out of the hole and slept on the ground.

Lying on the grass safe, she was curious about a question. How many metres was the “lucky place” down under the ground? She remembered that the sum of the times of her climbing up and falling down is n(of course, n is odd), so the distance between the ground and the “lucky place” must be 1-q+q2-q3+...+(-1)n-1qn-1. Snail Alice simplified that long formula and get a beautiful result: (qn+1)/(q+1). But as a math professor, she wouldn’t stop. She came up with a good problem to test her students. Here is the problem:

A function f(n), n is a positive integer, and
__poj_jax_start__f(n)=\left\{\begin{array}{cl}\frac{q^n+1}{q+1} & n\ is\ odd\\ \frac{q^n-1}{q+1} & n\ is\ even\end{array}\right.__poj_jax_end__f(n)=\left\{\begin{array}{cl}\frac{q^n+1}{q+1} & n\ is\ odd\\ \frac{q^n-1}{q+1} & n\ is\ even\end{array}\right.


Given q and n, please calculate the value of f(n).Please note that q and n could be huge.
输入解释
Input consists of multiple test cases, and ends with a line of “-1 -1 -1”.
For each test case:
The first line contains three integers x1, y1 and z1, representing q. q=x1y1+z1.
The second line contains two integers: y2 and z2, representing n. n=2y2+z2.
The third line contains a single integer P, meaning that what you really should output is the formula’s value mod P.
Note: 0<=x1,y1,z1,y2,z2<=50000, z1>0, 0<P<100000000
输出解释
For each test case, print one line containing an integer which equals to the formula’s value mod P.
输入样例
2 1 3
0 0
32551
3 0 5
0 2	
70546
-1 -1 -1
输出样例
1
31

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3777

最后修改于 2020-10-29T07:11:08+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
3000 65536