trafik

Untitled

Dec 19th, 2022
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long
  4. #define ld long double
  5. #define len(v) (int)v.size()
  6. #define all(v) v.begin(), v.end()
  7. #define rall(v) v.rbegin(), v.rend()
  8. #define pii pair<int, int>
  9. #define vi vector<int>
  10. #define vii vector<vector<int>>
  11. #define vpii vector<pair<int, int>>
  12. #define ull unsigned long long
  13. #define dcout cout << setprecision(7)
  14. //#define int long long
  15. //#define ll ull
  16. const int maxn = 110;
  17. const int C = 20;
  18. const int logn = 20;
  19. const int inf = 1e9;
  20. const ll mod = 1e9 + 7;
  21. const int M = 1e9;
  22. const ull M2 = 998244353;
  23. const ld eps = 1e-9;
  24. using namespace std;
  25.  
  26. // random
  27. //std::mt19937_64 gen(std::chrono::steady_clock::now().time_since_epoch().count());
  28.  
  29. template<class T>
  30. istream &operator>>(istream &in, vector<T> &a) {
  31.     for (auto &i : a)
  32.         in >> i;
  33.     return in;
  34. }
  35.  
  36. template<class T>
  37. ostream &operator<<(ostream &out, vector<T> &a) {
  38.     for (auto &i : a)
  39.         out << i;
  40.     return out;
  41. }
  42.  
  43. int binpow (int a, int n) {
  44.     if (n == 0)
  45.         return 1;
  46.     if (n % 2 == 1)
  47.         return binpow (a, n-1) * a;
  48.     else {
  49.         int b = binpow (a, n/2);
  50.         return b * b;
  51.     }
  52. }
  53.  
  54. __int128 a, b, k, m, x;
  55.  
  56. bool ok (__int128 d) {
  57.     __int128 s = (d-(d/k))*a;
  58.     s += (d-(d/m))*b;
  59.  
  60.     if (s>=x)
  61.         return true;
  62.     return false;
  63. }
  64.  
  65. void print(__int128 x) {
  66.     if (x < 0) {
  67.         putchar('-');
  68.         x = -x;
  69.     }
  70.     if (x > 9) print(x / 10);
  71.     putchar(x % 10 + '0');
  72. }
  73.  
  74. __int128 read() {
  75.     __int128 x = 0, f = 1;
  76.     char ch = getchar();
  77.     while (ch < '0' || ch > '9') {
  78.         if (ch == '-') f = -1;
  79.         ch = getchar();
  80.     }
  81.     while (ch >= '0' && ch <= '9') {
  82.         x = x * 10 + ch - '0';
  83.         ch = getchar();
  84.     }
  85.     return x * f;
  86. }
  87.  
  88. void solve() {
  89.     a = read();
  90.     k = read();
  91.     b = read();
  92.     m = read();
  93.     x = read();
  94.     __int128 l = 0ull, r = x;
  95.     while (l + 1 < r) {
  96.         __int128 mid = (l + r) / 2ull;
  97.         if (ok(mid))
  98.             r = mid;
  99.         else
  100.             l = mid;
  101.     }
  102.     print(r);
  103. }
  104.  
  105. signed main() {
  106.     ios::sync_with_stdio(false);
  107.     cin.tie(nullptr);
  108.     cout.tie(nullptr);
  109.  
  110.     int T = 1;
  111.     //cin >> T;
  112.     while (T--) {
  113.         solve();
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment