Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <numeric>
- #include <set>
- #include <queue>
- #include <stack>
- #include <vector>
- #include <climits>
- using namespace std;
- long long x, n, m;
- long long power(long long a, long long b)
- {
- if ( b == 0)
- {
- return 1;
- }
- long long t = power(a, b/2);
- if (b % 2 == 0)
- {
- return (t*t) % m;
- }
- else
- {
- return ((t*t)%m*a)%m;
- }
- }
- void read()
- {
- cin >> x >> n >> m;
- m *= (x-1);
- }
- void solve()
- {
- if(x == 1)
- {
- cout << n; return ;
- }
- cout << (power(x, n + 1) - 1)/(x-1);
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- read();
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement