A Simple Problem
Practice
0 (0 votes)
Medium
Problem
52% Success 136 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
This problem is quite simple. Your task is to calculate the sum of a geometric progression series.
You are given 3 integers R,N and M.
You have to calculate \((R + R^2 + ... + R^N) \bmod M\) .
INPUT :
First line contains an integer T, number of testcases.
\(1 \leq T \leq 10^3\)
Only line of each test case contains R, N and M.
\(1 \leq R,N,M \leq 10^8\)
OUTPUT :
Print answer to each testcase in a new line.
Submissions
Please login to view your submissions
Similar Problems
Points:30
Tags:
Modular exponentiationMediumMatrix ExponentiationMathematics
Points:30
Points:30
9 votes
Tags:
Linear AlgebraDynamic ProgrammingAlgorithmsMatrix ExponentiationMath
Editorial
No editorial available for this problem.