Advertisement
tien_noob

Nghịch Đảo Modulo - Cấp số nhân

Feb 4th, 2021 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <numeric>
  4. #include <set>
  5. #include <queue>
  6. #include <stack>
  7. #include <vector>
  8. #include <climits>
  9. using namespace std;
  10. long long x, n, m;
  11. long long power(long long a, long long b)
  12. {
  13.     if ( b == 0)
  14.     {
  15.         return 1;
  16.     }
  17.     long long t = power(a, b/2);
  18.     if (b % 2 == 0)
  19.     {
  20.         return (t*t) % m;
  21.     }
  22.     else
  23.     {
  24.         return ((t*t)%m*a)%m;
  25.     }
  26. }
  27. void read()
  28. {
  29.    cin >> x >> n >> m;
  30.    m *= (x-1);
  31. }
  32. void solve()
  33. {
  34.    if(x == 1)
  35.    {
  36.        cout << n; return ;
  37.    }
  38.    cout << (power(x, n + 1) - 1)/(x-1);
  39. }
  40. int main()
  41. {
  42.    ios_base::sync_with_stdio(false);
  43.    cin.tie(nullptr);
  44.    read();
  45.    solve();
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement