Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ull unsigned long long
- #define ld long double
- #define len(v) (int)v.size()
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define pii pair<int, int>
- #define vi vector<int>
- #define vii vector<vector<int>>
- #define vpii vector<pair<int, int>>
- #define ull unsigned long long
- #define dcout cout << setprecision(7)
- //#define int long long
- //#define ll ull
- const int maxn = 110;
- const int C = 20;
- const int logn = 20;
- const int inf = 1e9;
- const ll mod = 1e9 + 7;
- const int M = 1e9;
- const ull M2 = 998244353;
- const ld eps = 1e-9;
- using namespace std;
- // random
- //std::mt19937_64 gen(std::chrono::steady_clock::now().time_since_epoch().count());
- template<class T>
- istream &operator>>(istream &in, vector<T> &a) {
- for (auto &i : a)
- in >> i;
- return in;
- }
- template<class T>
- ostream &operator<<(ostream &out, vector<T> &a) {
- for (auto &i : a)
- out << i;
- return out;
- }
- int binpow (int a, int n) {
- if (n == 0)
- return 1;
- if (n % 2 == 1)
- return binpow (a, n-1) * a;
- else {
- int b = binpow (a, n/2);
- return b * b;
- }
- }
- __int128 a, b, k, m, x;
- bool ok (__int128 d) {
- __int128 s = (d-(d/k))*a;
- s += (d-(d/m))*b;
- if (s>=x)
- return true;
- return false;
- }
- void print(__int128 x) {
- if (x < 0) {
- putchar('-');
- x = -x;
- }
- if (x > 9) print(x / 10);
- putchar(x % 10 + '0');
- }
- __int128 read() {
- __int128 x = 0, f = 1;
- char ch = getchar();
- while (ch < '0' || ch > '9') {
- if (ch == '-') f = -1;
- ch = getchar();
- }
- while (ch >= '0' && ch <= '9') {
- x = x * 10 + ch - '0';
- ch = getchar();
- }
- return x * f;
- }
- void solve() {
- a = read();
- k = read();
- b = read();
- m = read();
- x = read();
- __int128 l = 0ull, r = x;
- while (l + 1 < r) {
- __int128 mid = (l + r) / 2ull;
- if (ok(mid))
- r = mid;
- else
- l = mid;
- }
- print(r);
- }
- signed main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int T = 1;
- //cin >> T;
- while (T--) {
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment