Geometric Progression Term Mod

Geometric Progression Term Mod

Medium Computer Mathematics Recurrences 23 views
Explanation Complexity

Problem Statement

Given a,r,n,m compute a*r^(n-1) mod m.

Input Format

a r n m.

Output Format

One integer.

Example

2 3 5 100
62

Constraints

n up to 1e18

Input / Output Format

Input Format
a r n m.
Output Format
One integer.
Constraints
n up to 1e18

Examples

Input:
2 3 5 100
Output:
62

Example Solution (Public)

Computer Mathematics
Compute powMod(r,n-1,m) then multiply by a mod m.

Official Solution Code

Compute powMod(r,n-1,m) then multiply by a mod m.
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.