PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000324. Tổng cấp số nhân (Geometric Progression)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng cấp số nhân (Geometric Progression)
Geometric Progression
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given positive integers , consider the sum of the first powers of :
Compute the non-negative remainder of modulo . The modulus is not necessarily prime, so modular division by may be invalid.
Input
One line contains three positive integers .
Output
Print the integer satisfying and .
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Example 1
Input
3 4 7
Output
5
Explanation
The sum is , and .
Example 2
Input
8 10 9
Output
0
Explanation
Modulo , we have . The ten terms form five pairs, each summing to .
Example 3
Input
1000000000 1000000000000 998244353
Output
919667211
Explanation
The exponent is too large for term-by-term summation. Repeatedly doubling block lengths gives the remainder .