#P8774. [蓝桥杯 2022 省 A] 爬树的甲壳虫
[蓝桥杯 2022 省 A] 爬树的甲壳虫
Problem Description
A beetle wants to climb a tree of height . It starts at the root, at height . When it tries to climb from height to height , it falls back to the root with probability . Find the expected time it takes to climb from the root to the top of the tree.
Input Format
The first line contains an integer , the height of the tree.
The next lines each contain two integers , separated by a space, meaning .
Output Format
Output one line containing one integer, representing the answer. The answer is a rational number; output its value modulo the prime . For a rational number , its value modulo a prime is the integer such that and .
1
1 2
2
3
1 2
3 5
7 11
623902744
Hint
Constraints:
For of the testdata, , .
For of the testdata, , .
For all testdata, , .
Lanqiao Cup 2022 NOI Qualifier A Group, Problem E.
Translated by ChatGPT 5