tien_noob

BONUS - (Important Calculation)

Apr 2nd, 2021 (edited)
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 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. #include <string>
  10. #include <cstdio>
  11. #include <cmath>
  12. #define task "BONUS"
  13. using namespace std;
  14. const int mod =  111539768;
  15. long long m, n, k, x, y, u, v;
  16. void read()
  17. {
  18.    cin >> m >> n >> k >> x >> y >> u >> v;
  19. }
  20. long long power(long long a, long long b)
  21. {
  22.     if (b == 0)
  23.     {
  24.         return 1;
  25.     }
  26.     long long t = power(a, b/2);
  27.     if (b % 2 == 0)
  28.     {
  29.         return (t * t)%mod;
  30.     }
  31.     else
  32.     {
  33.         return ((t * t) % mod * a) % mod;
  34.     }
  35. }
  36. long long G(long long a, long long b) // 1 + a + a^1 + .. + a ^ b
  37. {
  38.     if (b == 0)
  39.     {
  40.         return 1;
  41.     }
  42.     if (b == 1)
  43.     {
  44.         return 1 + a;
  45.     }
  46.     if (b % 2 == 1)
  47.     {
  48.         return (1 + a * G(a, b - 1)) % mod;
  49.     }
  50.     if (b % 2 == 0)
  51.     {
  52.         return ( (1 + power(a, b/2)) * (G(a, b/2) - 1) + 1) % mod;
  53.     }
  54. }
  55. long long F(long long a, long long b, long long c) // k ^ a + k^a + 1 +.. + k ^ b
  56. {
  57.     return (power(c, a) * G(c, b - a))%mod;
  58. }
  59. void solve()
  60. {
  61.    long long base1 = F((x - 1)*n + y - 1, (x - 1)*n + v - 1, k), base2 = power(k, n);
  62.    cout << (base1 * G(base2, u - x)) % mod;
  63. }
  64. int main()
  65. {
  66.    ios_base::sync_with_stdio(false);
  67.    cin.tie(nullptr);
  68.    freopen(task".INP", "r", stdin);
  69.    freopen(task".OUT", "w", stdout);
  70.    read();
  71.    solve();
  72. }
  73.  
Add Comment
Please, Sign In to add comment