Sum of a geometric sequence
Time limit0.5sMemory limit128 MB
Add the first n terms of a geometric sequence with first term a and ratio r, then print the sum modulo mod.
- Level
Medium5 of 10
- Topics
- Divide and conquer, Math, Recursion
- Solved
- No attempts yet
Problem
A geometric sequence has first term and common ratio . Add its first terms and find the remainder of that total divided by .
That is, print modulo .
Input
The first line contains , , , and , separated by spaces. All four are natural numbers greater than or equal to and less than or equal to .
Output
On the first line, print the remainder of the sequence sum divided by .