text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; long long c[10]; int main() { int t; scanf("%d", &t); while (t--) { long long x, y, ans = 0; scanf("%lld %lld", &x, &y); for (int i = 1; i <= 6; ++i) { scanf("%lld", &c[i]); } for (int i = 1; i <= 6; ++i) { int j = i - 1, k = i + 1; if (!j) j = 6; if (k > 6) k %= 6; c[i] = min(c[i], c[j] + c[k]); } if (x >= 0 && y >= 0) { long long tmp = min(x, y); ans = c[1] * tmp + c[2] * (y - tmp) + c[6] * (x - tmp); } else if (x >= 0 && y < 0) { ans = c[6] * x - c[5] * y; } else if (x < 0 && y >= 0) { ans = c[2] * y - c[3] * x; } else { long long tmp = min(-x, -y); ans = c[4] * tmp - c[5] * (y + tmp) - c[3] * (x + tmp); } printf("%lld\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; long long modexpo(long long x, long long p) { long long res = 1; x = x % 1000000007; while (p) { if (p % 2) res = res * x; p >>= 1; x = x * x % 1000000007; res %= 1000000007; } return res; } struct compare { bool operator()(const pair<long long, long long> a, const pair<long long, long long> b) const { return a.first < b.first; } }; void __solve__(long long testCase) { long long x, y, ans = 2e18 + 7; cin >> y >> x; vector<long long> c(6); for (long long &e : c) cin >> e; for (long long i = 0; i < 3; i++) for (long long j = 0; j < 3; j++) { long long s = 0; if (i == j) { if (i == 0 && y == 0) if (x > 0) s += c[1] * x; else s += c[4] * -x; if (i == 1 && x == 0) if (y > 0) s += c[5] * y; else s += c[2] * -y; if (i == 2 && x == y) if (x > 0) s += c[0] * x; else s += c[3] * -x; if (s) ans = min(ans, s); continue; } else if (i != 2 && j != 2) { if (x > 0) s += c[1] * x; else s += c[4] * -x; if (y > 0) s += c[5] * y; else s += c[2] * -y; } else { if (j == 0 || i == 0) { if (y > 0) s += c[0] * y; else s += c[3] * -y; if (x - y > 0) s += c[1] * (x - y); else s += c[4] * -(x - y); } else { if (x > 0) s += c[0] * x; else s += c[3] * -x; if (y - x > 0) s += c[5] * (y - x); else s += c[2] * -(y - x); } } ans = min(ans, s); } cout << ans << '\n'; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long testCase = 1; cin >> testCase; for (long long tc = 1; tc <= testCase; tc++) { __solve__(tc); } }
#include <bits/stdc++.h> using namespace std; void solve() { int x, y; cin >> y >> x; long long c[6]; for (long long& i : c) cin >> i; long long cost1 = x * (x > 0 ? c[1] : -c[4]) + y * (y > 0 ? c[5] : -c[2]), cost2 = x * (x > 0 ? c[0] : -c[3]) + (y - x) * (y - x > 0 ? c[5] : -c[2]), cost3 = (x - y) * (x - y > 0 ? c[1] : -c[4]) + y * (y > 0 ? c[0] : -c[3]); cout << min({cost1, cost2, cost3}); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; cin >> t; while (t--) { solve(); cout << '\n'; } return 0; }
#include <bits/stdc++.h> void err() { std::cout << std::endl; } template <typename T, typename... Args> void err(T a, Args... args) { std::cout << a << ' '; err(args...); } template <template <typename...> class T, typename t, typename... A> void err(const T<t> &arg, const A &...args) { for (auto &v : arg) std::cout << v << ' '; err(args...); } using namespace std; const long long mod = 1000000007; const int INF = 0x3f3f3f3f; const double PI = acos(-1.0); long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } const int N = 1e5 + 5; long long C[3][2]; void solve() { long long x, y; cin >> x >> y; cin >> C[0][0] >> C[2][0] >> C[1][1] >> C[0][1] >> C[2][1] >> C[1][0]; long long ans = 3e18; int d1 = 0, d2 = 0; if (x < 0) d1 = 1; if (x > y) d2 = 1; ans = min(ans, C[0][d1] * abs(x) + abs(x - y) * C[2][d2]); d1 = 0, d2 = 0; if (y < 0) d1 = 1; if (y > x) d2 = 1; ans = min(ans, C[0][d1] * abs(y) + abs(x - y) * C[1][d2]); d1 = 0, d2 = 0; if (x < 0) d1 = 1; if (y < 0) d2 = 1; ans = min(ans, C[1][d1] * abs(x) + abs(y) * C[2][d2]); cout << ans << endl; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); int T; cin >> T; while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; struct QuickRead { QuickRead() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } } quickread; void solve(); int main() { int t; cin >> t; while (t--) { solve(); } return 0; } long long directions[6][2] = {{1, 1}, {0, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, 0}}; long long solve(int x, int y, int d1, int d2, long long cost1, long long cost2) { long long a = directions[d1][0], b = directions[d1][1]; long long c = directions[d2][0], d = directions[d2][1]; long long det = a * d - b * c; if (det == 0) return -1; long long k1 = (x * d - y * c) / det; long long k2 = (a * y - b * x) / det; if (k1 < 0 || k2 < 0) return -1; return cost1 * k1 + cost2 * k2; } void solve() { long long x, y; cin >> x >> y; long long cost[6]; for (int i = 0; i < 6; ++i) cin >> cost[i]; long long ret = -1; for (int i = 0; i < 6; ++i) { for (int j = 0; j < i; ++j) { long long current = solve(x, y, i, j, cost[i], cost[j]); if (current == -1) continue; ret = (ret == -1) ? current : min(ret, current); } } cout << ret << "\n"; }
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const int mod1 = 9999973; const int mod2 = 1e9 + 7; inline int rd() { int f = 1, x = 0; char s = getchar(); while (!isdigit(s)) { if (s == '-') f = -1; s = getchar(); } while (isdigit(s)) { x = x * 10 + s - '0'; s = getchar(); } return x * f; } const int maxn = 1e5 + 10; char s[maxn]; int c[7]; int main() { int t; scanf("%d", &t); while (t--) { int x, y; scanf("%d %d", &x, &y); for (int i = 1; i <= 6; ++i) scanf("%llu", &c[i]); for (int i = 0; i < 6; ++i) { c[1] = min(c[1], c[2] + c[6]); c[2] = min(c[2], c[1] + c[3]); c[3] = min(c[3], c[4] + c[2]); c[4] = min(c[4], c[3] + c[5]); c[5] = min(c[5], c[4] + c[6]); c[6] = min(c[6], c[1] + c[5]); } if (x == 0 || y == 0) { if (x == 0 && y == 0) printf("0\n"); else if (x == 0) { unsigned long long ans = 0; if (y > 0) ans = (unsigned long long)y * (unsigned long long)c[2]; else { y = -y; ans = (unsigned long long)y * (unsigned long long)c[5]; } printf("%llu\n", ans); } else { unsigned long long ans = 0; if (x > 0) ans = (unsigned long long)x * (unsigned long long)c[6]; else { x = -x; ans = (unsigned long long)x * (unsigned long long)c[3]; } printf("%llu\n", ans); } } else if (x > 0 && y > 0) { unsigned long long ans = 0; if (x < y) { ans += (unsigned long long)x * (unsigned long long)c[1] + (unsigned long long)(y - x) * (unsigned long long)c[2]; } else { ans += (unsigned long long)y * (unsigned long long)c[1] + (unsigned long long)(x - y) * (unsigned long long)c[6]; } printf("%llu\n", ans); } else if (x < 0 && y < 0) { x = -x, y = -y; unsigned long long ans = 0; if (x < y) { ans += (unsigned long long)x * (unsigned long long)c[4] + (unsigned long long)(y - x) * (unsigned long long)c[5]; } else { ans += (unsigned long long)y * (unsigned long long)c[4] + (unsigned long long)(x - y) * (unsigned long long)c[3]; } printf("%llu\n", ans); } else if (x > 0 && y < 0) { unsigned long long ans = 0; y = -y; ans += (unsigned long long)x * (unsigned long long)c[6] + (unsigned long long)y * (unsigned long long)c[5]; printf("%llu\n", ans); } else { unsigned long long ans = 0; x = -x; ans += (unsigned long long)x * (unsigned long long)c[3] + (unsigned long long)y * (unsigned long long)c[2]; printf("%llu\n", ans); } } return 0; }
#include <bits/stdc++.h> using namespace std; pair<long long, long long> a[7] = {{}, {1, 1}, {0, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, 0}}; long long c[7]; map<pair<long long, long long>, long long> real_cost; void opt(long long cost, long long len, pair<long long, long long> cell) { if (len == 6) { real_cost[cell] = min(real_cost[cell], cost); return; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long t; cin >> t; while (t--) { long long c1, c2, c3, c4, c5, c6; long long x, y; cin >> y >> x; for (long long i = 1; i <= 6; ++i) { cin >> c[i]; } for (long long i = 1; i <= 6; ++i) { real_cost[a[i]] = c[i]; } for (long long i = 1; i < (1 << 6); ++i) { long long cost = 0; pair<long long, long long> cell = {0, 0}; for (long long j = 0; j < 6; ++j) { if ((i >> j) & 1) { cost += c[j + 1]; cell.first += a[j + 1].first; cell.second += a[j + 1].second; } } real_cost[cell] = min(real_cost[cell], cost); } long long res = 0; if (x < 0) { res = abs(x) * real_cost[a[5]]; } else { res = x * real_cost[a[2]]; } if (y < 0) { res += abs(y) * real_cost[a[3]]; } else { res += y * real_cost[a[6]]; } long long xabs = abs(x); long long yabs = abs(y); if (x > 0 && y > 0) { long long cur = real_cost[a[1]] * min(xabs, yabs) + (xabs > yabs ? real_cost[a[2]] * (xabs - yabs) : real_cost[a[6]] * (yabs - xabs)); res = min(res, cur); } else if (x < 0 && y < 0) { long long cur = real_cost[a[4]] * min(xabs, yabs) + (xabs > yabs ? real_cost[a[5]] * (xabs - yabs) : real_cost[a[3]] * (yabs - xabs)); res = min(res, cur); } cout << res << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long double PI = 3.141592653589793238462643383279502884197; long long fac[1] = {1}, inv[1] = {1}; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long mp(long long a, long long b) { long long ret = 1; while (b) { if (b & 1) ret = ret * a % MOD; a = a * a % MOD; b >>= 1; } return ret; } long long cmb(long long r, long long c) { return (c > r || c < 0) ? 0 : fac[r] * inv[c] % MOD * inv[r - c] % MOD; } map<pair<int, int>, int> ma; int main() { int tc; scanf("%d", &tc); while (tc--) { long long x, y; scanf("%lld %lld", &x, &y); long long a, b, c, d, e, f; scanf("%lld %lld %lld %lld %lld %lld", &a, &b, &c, &d, &e, &f); for (int cnt = 0; cnt < 100; cnt++) { a = min(a, b + f); b = min(b, a + c); c = min(c, b + d); d = min(d, c + e); e = min(e, d + f); f = min(f, e + a); } ma[{1, 1}] = a; ma[{0, 1}] = b; ma[{-1, 0}] = c; ma[{-1, -1}] = d; ma[{0, -1}] = e; ma[{1, 0}] = f; long long ans = 9e18; if (x * y < 0) { long long q = 1, w = 1; if (x < 0) q = -1; if (y < 0) w = -1; ans = min(ans, ma[{q, 0}] * abs(x) + ma[{0, w}] * abs(y)); } else { long long q = 1, w = 1; if (x < 0) q = -1; if (y < 0) w = -1; x = abs(x); y = abs(y); long long ck = abs(x - y); ans = min(ans, ma[{q, w}] * min(x, y) + (x > y ? ma[{q, 0}] * ck : ma[{0, w}] * ck)); } printf("%lld\n", ans); } }
#include <bits/stdc++.h> using namespace std; using LL = long long; int T, N, K; LL X, Y, C[7]; LL gain(LL dir, LL b, LL c, LL &step) { LL d = C[4] + (b >= 0 ? C[6] : -C[3]) + (c >= 0 ? C[2] : -C[5]); if (dir > 0) d = C[1] + (b > 0 ? -C[6] : C[3]) + (c > 0 ? -C[2] : C[5]); if (dir > 0) { if (min(b, c) > 0) step = abs(min(b, c)); else step = abs(max(b, c)); } else { if (max(b, c) < 0) step = abs(max(b, c)); else step = abs(min(b, c)); } return d; } LL test(LL dir, LL a, LL b, LL c, LL start) { LL ans = start; for (;;) { LL step = -1; LL d = gain(dir, b, c, step); if (d < 0) { a += dir * step; b -= dir * step; c -= dir * step; start += d * step; ans = min(ans, start); continue; } break; } return ans; } int main() { scanf("%d", &T); while (T--) { scanf("%lld %lld", &X, &Y); for (int i = 1; i <= 6; ++i) scanf("%lld", C + i); LL a = 0, b = X, c = Y; LL ans = (b > 0 ? C[6] * abs(b) : C[3] * abs(b)) + (c > 0 ? C[2] * abs(c) : C[5] * abs(c)); printf("%lld\n", min(test(1, a, b, c, ans), test(-1, a, b, c, ans))); } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; template <typename T, typename TT> inline ostream &operator<<(ostream &os, const pair<T, TT> &t) { return os << t.first << " " << t.second; } template <typename T> inline ostream &operator<<(ostream &os, const vector<T> &t) { for (auto i : t) os << i << " "; return os; } template <typename T> inline ostream &operator<<(ostream &os, const set<T> &t) { for (auto i : t) os << i << " "; return os; } template <typename T1, typename T2> inline ostream &operator<<(ostream &os, const map<T1, T2> &t) { for (auto i : t) os << i.first << " : " << i.second << '\n'; return os; } template <typename T> inline istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; } template <typename T1, typename T2> inline istream &operator>>(istream &is, vector<pair<T1, T2>> &v) { for (pair<T1, T2> &t : v) is >> t.first >> t.second; return is; } const long long mod = 1e9 + 7; void solve() { long long x, y; cin >> x >> y; vector<long long> c(6); cin >> c; long long ans = 1e18; for (int i = 0; i < 3; i++) { c[0] = min(c[0], c[1] + c[5]); c[1] = min(c[1], c[0] + c[2]); c[2] = min(c[2], c[3] + c[1]); c[3] = min(c[3], c[2] + c[4]); c[4] = min(c[4], c[3] + c[5]); c[5] = min(c[5], c[0] + c[4]); } if (x >= 0) { if (y >= 0) { ans = c[5] * x + c[1] * y; ans = min(ans, min(x, y) * c[0] + (x - min(x, y)) * c[5] + (y - min(x, y)) * c[1]); } else { y = -y; ans = c[5] * x + c[4] * abs(y); ans = min(ans, x * c[0] + (x + y) * c[4]); ans = min(ans, y * c[3] + (x + y) * c[5]); } } else { x = -x; if (y >= 0) { ans = c[2] * x + c[1] * y; ans = min(ans, c[0] * y + (x + y) * c[2]); ans = min(ans, c[3] * x + (x + y) * c[1]); } else { y = -y; ans = c[2] * x + y * c[4]; ans = min(ans, c[3] * min(x, y) + (x - min(x, y)) * c[2] + (y - min(x, y)) * c[4]); } } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ; long long T = 1; cin >> T; while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const int nax = 1e9 + 7; const int mod = 1e9 + 7; const int inf = 1e9 + 7; const long long infll = 1e18 + 7; const long double PI = 3.1415926535897932384626433832795; void solve() { long long x, y; long long c[6]; cin >> y >> x; for (int i = 0; i < 6; ++i) { cin >> c[i]; } long long ans = infll; if (x >= 0 && y >= 0) { ans = x * c[1] + y * c[5]; if (x > y) { ans = min(ans, y * c[0] + (x - y) * c[1]); ans = min(ans, x * c[0] + (x - y) * c[2]); } else { ans = min(ans, x * c[0] + (y - x) * c[5]); ans = min(ans, y * c[0] + (y - x) * c[4]); } } else if (x < 0 && y >= 0) { x = -x; ans = x * c[4] + y * c[5]; ans = min(ans, (x + y) * c[4] + y * c[0]); ans = min(ans, (x + y) * c[5] + x * c[3]); } else if (x < 0 && y < 0) { x = -x, y = -y; ans = x * c[4] + y * c[2]; if (x > y) { ans = min(ans, (x - y) * c[4] + y * c[3]); ans = min(ans, x * c[3] + (x - y) * c[5]); } else { ans = min(ans, (y - x) * c[2] + x * c[3]); ans = min(ans, y * c[3] + (y - x) * c[1]); } } else if (x >= 0 && y < 0) { y = -y; ans = x * c[1] + y * c[2]; ans = min(ans, x * c[0] + (x + y) * c[2]); ans = min(ans, y * c[3] + (x + y) * c[1]); } else { } printf("%lld\n", ans); } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t = 1; cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10, inf = 0x3f3f3f3f, mod = 1000000007; const long long INF = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-9; void read() {} template <typename T, typename... T2> inline void read(T &x, T2 &...oth) { x = 0; int ch = getchar(), f = 0; while (ch < '0' || ch > '9') { if (ch == '-') f = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } if (f) x = -x; read(oth...); } signed main(signed argc, char const *argv[]) { std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); long long t, x, y, c[7]; cin >> t; while (t--) { cin >> x >> y; for (int i = 1; i <= 6; i++) cin >> c[i]; c[1] = min(c[1], c[2] + c[6]); c[2] = min(c[2], c[1] + c[3]); c[3] = min(c[3], c[2] + c[4]); c[4] = min(c[4], c[3] + c[5]); c[5] = min(c[5], c[4] + c[6]); c[6] = min(c[6], c[1] + c[5]); long long d1 = x, d2 = y, d3; long long ans = 0; if (d1 > 0) ans += c[6] * d1; else ans -= c[3] * d1; if (d2 > 0) ans += c[2] * d2; else ans -= c[5] * d2; if (d1 > 0 && d2 > 0) { long long num = min(d1, d2); if (c[6] + c[2] > c[1]) ans -= num * (c[6] + c[2] - c[1]); } else if (d1 < 0 && d2 < 0) { long long num = min(abs(d1), abs(d2)); if (c[3] + c[5] > c[4]) ans -= num * (c[3] + c[5] - c[4]); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; constexpr long long MOD = 998244353; constexpr long long mod = 1e9 + 7; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const long long N = 3e5 + 5; vector<long long> adj[N]; long long power(long long n, long long p) { if (p == 0) return 1; if (p == 1) return n; if (p % 2) return power(n, p - 1) * n; else { long long x = power(n, p / 2); return x * x; } } long long modpow(long long a, long long b, long long m) { long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; } long long nsum(long long num) { return (num * (num + 1)) / 2; } void edge(long long u, long long v) { adj[u].push_back(v); adj[v].push_back(u); } void solve() { long long x, y, c1, c2, c3, c4, c5, c6; string s; cin >> x >> y; cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6; c1 = min(c1, c6 + c2); c2 = min(c2, c1 + c3); c3 = min(c3, c2 + c4); c4 = min(c4, c3 + c5); c5 = min(c5, c4 + c6); c6 = min(c6, c5 + c1); long long ans = 0; if (x >= 0 && y >= 0) { long long mn = min(x, y); x -= mn; y -= mn; ans += mn * c1; } if (x < 0 && y < 0) { long long mn = max(x, y); x -= mn; y -= mn; ans += abs(mn) * c4; } if (x >= 0) { ans += x * c6; } if (x < 0) { ans += abs(x) * c3; } if (y >= 0) { ans += y * c2; } if (y < 0) ans += abs(y) * c5; cout << ans << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long Test = 1; cin >> Test; while (Test--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t > 0) { long long x, y, c1, c2, c3, c4, c5, c6, comp1, comp2, comp3, comp4, comp5, comp6, br1 = 0, br2 = 0, br3 = 0, br4 = 0, br5 = 0, br6 = 0; cin >> y >> x; cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6; comp1 = c2 + c6; comp2 = c1 + c3; comp3 = c2 + c4; comp4 = c3 + c5; comp5 = c4 + c6; comp6 = c5 + c1; if (y <= 0 and x >= 0) { br3 = -y; br2 = x; } if (y >= 0 and x <= 0) { br6 = y; br5 = -x; } if (y >= 0 and x >= y) { br1 = y; br2 = x - y; } if (y <= 0 and x <= y) { br4 = -y; br5 = y - x; } if (y <= 0 and x <= 0 and x >= y) { br4 = -x; br3 = x - y; } if (y >= 0 and x >= 0 and x <= y) { br1 = x; br6 = y - x; } long long ans = (br1 * min(c1, comp1)) + (br2 * min(c2, comp2)) + (br3 * min(c3, comp3)) + (br4 * min(c4, comp4)) + (br5 * min(c5, comp5)) + (br6 * min(c6, comp6)); cout << ans << '\n'; t--; } return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; inline int ksm(int a, int b) { int ans = 1; for (; b; b >>= 1, a = a * a % mod) if (b & 1) ans = ans * a % mod; return ans; } template <typename T> inline void read(T &x) { x = 0; int fu = 1; char c = getchar(); while (c > 57 || c < 48) { if (c == 45) fu = -1; c = getchar(); } while (c <= 57 && c >= 48) { x = (x << 3) + (x << 1) + c - 48; c = getchar(); } x *= fu; } template <typename T, typename... Args> inline void read(T &x, Args &...arg) { read(x); read(arg...); } template <typename T> inline void write(T x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) write(x / 10); putchar(x % 10 + '0'); } long long a[7]; long long ex, ey; long long make() { long long x, y; long long ans = 2e19; if (ex > 0) { x = ex, y = 0; if (ey > 0) ans = min(ans, x * a[5] + abs(ey) * a[1]); else ans = min(ans, x * a[5] + (abs(ey) * a[4])); x = ex, y = ex; if (ey > ex) ans = min(ans, x * a[0] + abs(ey - y) * a[1]); else ans = min(ans, x * a[0] + abs(y - ey) * a[4]); } else { x = ex, y = 0; if (ey > 0) ans = min(ans, -x * a[2] + abs(ey) * a[1]); else ans = min(ans, -x * a[2] + (abs(-ey) * a[4])); x = ex, y = ex; if (ey > ex) ans = min(ans, -x * a[3] + abs(ey - y) * a[1]); else ans = min(ans, -x * a[3] + abs(y - ey) * a[4]); } if (ex > 0 & 0 < ey && ey < ex) { ans = min(ans, ey * a[0] + abs(ex - ey) * a[5]); } else if (ex < 0 && ex < ey && ey < 0) { ans = min(ans, -ey * a[3] + abs(ex - ey) * a[2]); } return ans; } void work() { cin >> ex >> ey; for (long long i = 0; i <= 5; i++) { cin >> a[i]; } for (long long k = 1; k <= 10; k++) { long long p, l, pp, ll; for (long long i = 0; i <= 5; i++) { p = (i - 1 + 6) % 6; l = (i + 1 + 6) % 6; pp = (i - 2 + 6) % 6; ll = (i + 2 + 6) % 6; a[i] = min(a[i], a[l] + a[p]); } } long long ans = 0; ans = make(); cout << ans << endl; } signed main() { long long t; cin >> t; while (t--) work(); return 0; }
#include <bits/stdc++.h> using namespace std; long long x, y; long long bp, yp, xm, bm, ym, xp; long long cyp = 0, cxm = 0, cym = 0, cxp = 0; long long ans(long long cbp, long long cbm) { if (cbm == -1) { cbm = 0; cxm = max(0ll, cbp - x); cxp = max(0ll, x - cbp); cym = max(0ll, cbp - y); cyp = max(0ll, y - cbp); } else { cbp = 0; cxm = max(0ll, -cbm - x); cxp = max(0ll, x + cbm); cym = max(0ll, -cbm - y); cyp = max(0ll, y + cbm); } return cbp * bp + cbm * bm + cxp * xp + cxm * xm + cyp * yp + cym * ym; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { cin >> x >> y; cin >> bp >> yp >> xm >> bm >> ym >> xp; long long res = 2e18; long long abx = abs(x), aby = abs(y); res = min(res, ans(abx, -1)); res = min(res, ans(aby, -1)); res = min(res, ans(0, -1)); res = min(res, ans(-1, abx)); res = min(res, ans(-1, aby)); res = min(res, ans(-1, 0)); cout << res << "\n"; } return 0; }
#include <bits/stdc++.h> using ll = long long; using namespace std; const ll maxSize = 5007; ll c[7]; ll calc25(ll x) { return (x > 0) ? x * c[2] : -x * c[5]; } ll calc36(ll x) { return (x > 0) ? x * c[6] : -x * c[3]; } ll calc14(ll x) { return (x > 0) ? x * c[1] : -x * c[4]; } ll calcSum12(ll x, ll y) { return calc14(x) + calc25(y - x); } ll calcSum13(ll x, ll y) { return calc14(y) + calc36(x - y); } ll calcSum23(ll x, ll y) { return calc25(y) + calc36(x); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll q; cin >> q; while (q > 0) { ll x, y; cin >> x >> y; for (ll i = 1; i <= 6; ++i) cin >> c[i]; ll answer = min(calcSum12(x, y), calcSum13(x, y)); answer = min(answer, calcSum23(x, y)); cout << answer; --q; if (q > 0) cout << "\n"; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll c[10]; int dx[] = {1, 0, -1, -1, 0, 1}; int dy[] = {1, 1, 0, -1, -1, 0}; int main() { int t; cin >> t; while (t--) { ll x, y; cin >> x >> y; for (int i = 0; i < 6; ++i) cin >> c[i]; long long ans = 5e18; for (int i = 0; i < 6; ++i) { for (int j = i; j < 6; ++j) { int det = dx[i] * dy[j] - dx[j] * dy[i]; if (det != 0) { long long t1 = (x * dy[j] - y * dx[j]) / det; long long t2 = (dx[i] * y - dy[i] * x) / det; if (t1 >= 0 && t2 >= 0) { ans = min(ans, t1 * c[i] + t2 * c[j]); } } } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long x, y; int c1, c2, c3, c4, c5, c6; inline int read() { int res = 0; char ch = getchar(), ch1 = ch; while (!isdigit(ch)) ch1 = ch, ch = getchar(); while (isdigit(ch)) res = (res << 3) + (res << 1) + ch - '0', ch = getchar(); return ch1 == '-' ? -res : res; } int main() { for (register int T = read(); T; --T) { x = read(); y = read(); c1 = read(); c2 = read(); c3 = read(); c4 = read(); c5 = read(); c6 = read(); for (register int i = 0; i < 15; ++i) { c1 = min(c1, c2 + c6); c2 = min(c2, c1 + c3); c3 = min(c3, c2 + c4); c4 = min(c4, c3 + c5); c5 = min(c5, c4 + c6); c6 = min(c6, c1 + c5); } if (x <= 0 && y <= 0) printf("%lld\n", x >= y ? -x * c4 - (y - x) * c5 : -y * c4 - (x - y) * c3); else if (x >= 0 && y >= 0) printf("%lld\n", x <= y ? x * c1 + (y - x) * c2 : y * c1 + (x - y) * c6); else if (x >= 0 && y <= 0) printf("%lld\n", x * c6 - y * c5); else printf("%lld\n", -x * c3 + y * c2); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll c[10]; int dx[] = {1, 0, -1, -1, 0, 1}; int dy[] = {1, 1, 0, -1, -1, 0}; int main() { int t; cin >> t; while (t--) { ll x, y; cin >> x >> y; for (int i = 0; i < 6; ++i) cin >> c[i]; long long ans = 5e18; auto sign = [](long long x) { if (x == 0) return 0; if (x < 0) return -1; return 1; }; for (int i = 0; i < 6; ++i) { for (int j = i; j < 6; ++j) { int det = dx[i] * dy[j] - dx[j] * dy[i]; if (det != 0) { long long t1 = x * dy[j] - y * dx[j]; long long t2 = dx[i] * y - dy[i] * x; t1 /= det; t2 /= det; if (t1 >= 0 && t2 >= 0) { ans = min(ans, t1 * c[i] + t2 * c[j]); } } } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; const long long MAX = 1000000000; const long long LLONG = 9223372036854775807; const int N = 100000; const double EPS = 0.00000001; const int sqsz = 5000; template <typename T> inline int sgn(const T& val) { return (T(0) < val) - (val < T(0)); } inline unsigned long long hsh(int x, int y) { return (((unsigned long long)x) << 32) + y; } template <typename T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); } return a; } inline void fastio() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { long long x, y, c[6], res; int t; scanf("%i", &t); while (t--) { scanf("%lli %lli", &x, &y); for (int i = 0; i < 6; i++) scanf("%lli", c + i); c[0] = min(c[0], c[5] + c[1]); c[1] = min(c[1], c[0] + c[2]); c[2] = min(c[2], c[3] + c[1]); c[3] = min(c[3], c[2] + c[4]); c[4] = min(c[4], c[3] + c[5]); c[5] = min(c[5], c[4] + c[0]); if (x >= 0) { if (y >= 0) { res = c[0] * min(x, y) + c[5] * (x - min(x, y)) + c[1] * (y - min(x, y)); } else { y *= -1; res = c[5] * x + c[4] * y; } } else { x *= -1; if (y <= 0) { y *= -1; res = c[3] * min(x, y) + c[2] * (x - min(x, y)) + c[4] * (y - min(x, y)); } else { res = c[2] * x + c[1] * y; } } printf("%lli\n", res); } }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const double eps = 1e-6; const long long inf = 0x3f3f3f3f; const long long N = 2e5 + 10; char s[N]; int main() { long long t; scanf("%lld", &t); while (t--) { long long x, y; long long v1, v2, v3, v4, v5, v6; scanf("%lld%lld", &x, &y); scanf("%lld%lld%lld%lld%lld%lld", &v1, &v2, &v3, &v4, &v5, &v6); v1 = min(v1, v6 + v2); v2 = min(v2, v1 + v3); v3 = min(v3, v2 + v4); v4 = min(v4, v3 + v5); v5 = min(v5, v4 + v6); v6 = min(v6, v1 + v5); long long ans1 = 0LL; long long ans2 = 0LL; if (x * y == 0LL) { if (x == 0LL) { if (y >= 0) { ans1 += v2 * abs(y); } else { ans1 += v5 * abs(y); } } else { if (x >= 0) { ans1 += v6 * abs(x); } else { ans1 += v3 * abs(x); } } printf("%lld\n", ans1); } else if (x * y < 0LL) { if (x < 0LL) { ans1 += v3 * abs(x); ans1 += v2 * abs(y); } else { ans1 += v6 * abs(x); ans1 += v5 * abs(y); } printf("%lld\n", ans1); } else { if (x < 0LL) { if (x < y) { ans1 += v4 * abs(y); ans1 += v3 * abs(y - x); } else { ans1 += v4 * abs(x); ans1 += v5 * abs(x - y); } } else { if (x < y) { ans1 += abs(x) * v1; ans1 += v2 * abs(y - x); } else { ans1 += abs(y) * v1; ans1 += v6 * abs(x - y); } } printf("%lld\n", ans1); } } return 0; }
#include <bits/stdc++.h> using namespace std; bool imp = true; void solve() { long long n = 0, m = 0, i = 0, j = 0, k = 0, flag = 0, sum = 0; string s, t; long long x, y; cin >> x >> y; long long c[10]; for (i = 1; i <= 6; i++) cin >> c[i]; long long mx, my, px, py, pxy, mxy; my = min(c[4] + c[6], c[5]); py = min(c[1] + c[3], c[2]); mx = min(c[4] + c[2], c[3]); px = min(c[1] + c[5], c[6]); pxy = min({px + py, c[2] + c[6], c[1]}); mxy = min({mx + my, c[3] + c[5], c[4]}); if (x * y > 0) { if (x > 0 and y > 0) { k = min(x, y); x -= k; y -= k; cout << k * pxy + x * px + y * py << '\n'; } else { k = max(x, y); k = abs(k); x += k; y += k; cout << k * mxy + abs(x) * mx + abs(y) * my << '\n'; } } else { if (x >= 0 and y <= 0) cout << px * x + my * abs(y) << '\n'; else cout << mx * abs(x) + py * y << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t = 1; if (imp) cin >> t; long long j = t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; bool comp(long long a, long long b) { return a < b; } priority_queue<long long, vector<long long>, function<bool(long long a, long long b)>> p(comp); void A() { long long t; cin >> t; while (t--) { long long a, b; cin >> a >> b; a = a ^ b; cout << a << "\n"; } } void B() { long long t; cin >> t; while (t--) { long long n; cin >> n; string s[n]; for (long long i = 0; i < (long long)n; ++i) cin >> s[i]; vector<pair<long long, long long>> vt; if (s[0][1] != s[1][0]) { vt.push_back({0, 1}); } if (s[n - 2][n - 1] == s[1][0]) { vt.push_back({n - 2, n - 1}); } if (s[n - 1][n - 2] == s[1][0]) { vt.push_back({n - 1, n - 2}); } if (vt.size() == 3) { vt.clear(); if (s[0][1] != s[1][0]) { vt.push_back({1, 0}); } if (s[n - 2][n - 1] == s[0][1]) { vt.push_back({n - 2, n - 1}); } if (s[n - 1][n - 2] == s[0][1]) { vt.push_back({n - 1, n - 2}); } } assert(vt.size() <= 2); cout << vt.size() << "\n"; for (auto it : vt) cout << it.first + 1 << " " << it.second + 1 << "\n"; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t = 1; cin >> t; while (t--) { long long x, y; cin >> x >> y; long long c[6]; for (long long i = 0; i < (long long)6; ++i) cin >> c[i]; if (x >= 0 && y >= 0) { long long c1 = c[0] * min(x, y) + c[1] * (y - min(x, y)) + c[5] * (x - min(x, y)); long long c2 = c[1] * y + c[5] * x; long long c3 = c[0] * max(x, y) + c[2] * (max(x, y) - x) + c[4] * (max(x, y) - y); cout << min({c1, c2, c3}) << "\n"; } else if (x < 0 && y < 0) { x *= -1; y *= -1; long long c1 = c[3] * (min(x, y)) + c[4] * (y - min(x, y)) + c[2] * (x - min(x, y)); long long c2 = c[2] * x + c[4] * y; long long c3 = c[3] * max(x, y) + c[1] * (max(x, y) - y) + c[5] * (max(x, y) - x); cout << min({c1, c2, c3}) << "\n"; } else if (x < 0) { x *= -1; long long c1 = c[3] * (min(x, y)) + c[1] * (y + min(x, y)) + c[2] * (x - min(x, y)); long long c2 = c[2] * x + c[1] * y; long long c3 = c[3] * max(x, y) + c[1] * (max(x, y) + y) + c[5] * (max(x, y) - x); long long c4 = c[0] * min(x, y) + c[1] * (y - min(x, y)) + c[2] * (x + min(x, y)); long long c5 = c[0] * max(x, y) + c[4] * (max(x, y) - y) + c[2] * (x + max(x, y)); cout << min({c1, c2, c3, c4, c5}) << "\n"; } else { y *= -1; long long c1 = c[3] * (min(x, y)) + c[4] * (y - min(x, y)) + c[5] * (x + min(x, y)); long long c2 = c[5] * x + c[4] * y; long long c3 = c[3] * max(x, y) + c[1] * (max(x, y) - y) + c[5] * (max(x, y) + x); long long c4 = c[0] * min(x, y) + c[4] * (y + min(x, y)) + c[5] * (x - min(x, y)); long long c5 = c[0] * max(x, y) + c[4] * (max(x, y) + y) + c[2] * (max(x, y) - x); cout << min({c1, c2, c3, c4, c5}) << "\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; using pii = pair<long long, long long>; const int D = 6; const int dx[] = {1, 0, -1, -1, 0, 1}; const int dy[] = {1, 1, 0, -1, -1, 0}; int t, fx, fy, c[D]; map<pii, int> dir; pii solveEq(pii a, pii b, long long x, long long y) { long long ax = a.first; long long ay = a.second; long long bx = b.first; long long by = b.second; long long num = y * ax - x * ay; long long den = by * ax - bx * ay; if (den == 0 || num % den) { return {-1, -1}; } long long v2 = num / den; long long v1; if (ax != 0) { v1 = (x - v2 * bx) / ax; } else { v1 = (y - v2 * by) / ay; } return {v1, v2}; } long long solve() { cin >> fx >> fy; for (int i = 0; i < D; i++) { cin >> c[i]; } for (int i = 0; i < D; i++) { for (int j = 0; j < i; j++) { pii pos = {dx[i] + dx[j], dy[i] + dy[j]}; if (!dir.count(pos)) continue; int d = dir[pos]; int nc = c[i] + c[j]; c[d] = min(c[d], nc); } } long long ans = LLONG_MAX; for (int i = 0; i < D; i++) { for (int j = 0; j < i; j++) { pii d1 = {dx[i], dy[i]}; pii d2 = {dx[j], dy[j]}; auto [a, b] = solveEq(d1, d2, fx, fy); if (a < 0 || b < 0) continue; long long cost = a * 1LL * c[i] + b * 1LL * c[j]; ans = min(ans, cost); } } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); for (int i = 0; i < D; i++) { pii d = {dx[i], dy[i]}; dir[d] = i; } cin >> t; while (t--) { cout << solve() << '\n'; } return 0; }
#include <bits/stdc++.h> template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; template <class A, class B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << "(" << p.first << "," << p.second << ")"; } template <class A, class B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); int t; cin >> t; while (t--) { long long ans = LONG_LONG_MAX; long long X, Y; cin >> X >> Y; vector<long long> c(6); for (int i = 0; i < (int)(6); i++) cin >> c[i]; swap(c[2], c[5]); for (int i = 0; i < (int)(2); i++) for (int j = 0; j < (int)(2); j++) for (int k = 0; k < (int)(2); k++) { long long c1 = c[3 * i]; long long c2 = c[3 * j + 1]; long long c3 = c[3 * k + 2]; long long t = 0; long long l = 0LL, r = LONG_LONG_MAX; if (i == j) { t -= c2; if (i == 0) chmin(r, Y); else chmin(r, -Y); } else { t += c2; if (i == 0) chmax(l, Y); else chmax(l, -Y); } if (i == k) { t -= c3; if (i == 0) chmin(r, X); else chmin(r, -X); } else { t += c3; if (i == 0) chmax(l, X); else chmax(l, -X); } if (r < l) continue; long long a = 0; if (t >= 0) a = l; else a = r; long long s1 = (i == 1) ? -1 : 1; long long s2 = (j == i) ? -1 : 1; long long s3 = (k == i) ? -1 : 1; long long ss2 = (j == 1) ? -1 : 1; long long ss3 = (k == 1) ? -1 : 1; long long sum = 0; sum += a * c1; sum += (s2 * a + ss2 * Y) * c2; sum += (s3 * a + ss3 * X) * c3; chmin(ans, sum); } cout << ans << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int t, a, b, c1, c2, c3, c4, c5, c6, i; cin >> t; for (i = 0; i < t; i++) { cin >> a >> b; cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6; if (c1 > c6 + c2) c1 = c6 + c2; if (c2 > c1 + c3) c2 = c1 + c3; if (c3 > c4 + c2) c3 = c4 + c2; if (c4 > c5 + c3) c4 = c5 + c3; if (c5 > c6 + c4) c5 = c6 + c4; if (c6 > c5 + c1) c6 = c5 + c1; if (c1 > c6 + c2) c1 = c6 + c2; if (c2 > c1 + c3) c2 = c1 + c3; if (c3 > c4 + c2) c3 = c4 + c2; if (c4 > c5 + c3) c4 = c5 + c3; if (c5 > c6 + c4) c5 = c6 + c4; if (c6 > c5 + c1) c6 = c5 + c1; if ((a >= 0) && (b >= 0) && (b >= a)) cout << c1 * a + (b - a) * c2 << endl; else if ((a >= 0) && (b >= 0)) cout << c1 * b + c6 * (a - b) << endl; else if ((a >= 0) && (b <= 0)) cout << a * c6 - b * c5 << endl; else if ((a <= 0) && (b <= 0) && (a >= b)) cout << (a - b) * c5 - a * c4 << endl; else if ((a <= 0) && (b <= 0)) cout << (b - a) * c3 - b * c4 << endl; else cout << b * c2 - a * c3 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } long long int gcd(long long int a, long long int b) { if (a < b) return gcd(b, a); else if (b == 0) return a; else return gcd(b, a % b); } long long int isPrime(long long int n) { long long int p = (long long int)sqrt(n); for (int i = (2); i <= (p); i += (1)) if (n % i == 0) return 0; return 1; } long long int pow(long long int b, long long int e) { if (e == 0) return 1; else if (e % 2 == 0) { long long int a = pow(b, e / 2); return a * a; } else { long long int a = pow(b, e / 2); return b * a * a; } } long long int powm(long long int x, long long int y, long long int m = 1000000007) { x = x % m; long long int res = 1; while (y) { if (y & 1) res = res * x; res %= m; y = y >> 1; x = x * x; x %= m; } return res; } long long int modInverse(long long int a, long long int m) { return powm(a, m - 2, m); } void solve() { long long int x, y; cin >> x >> y; long long int c[7]; for (int i = (1); i <= (6); i += (1)) cin >> c[i]; long long int ans = LLONG_MAX; int isnegx = 1, isnegy = 1; if (x < 0) isnegx = -1; if (y < 0) isnegy = -1; swap(x, y); if (x >= 0 and y >= 0) { if (x <= y) { ans = min({ans, c[1] * x + (y - x) * c[6], c[1] * y + (y - x) * c[5], c[2] * x + c[6] * y}); } else { ans = min({ans, c[1] * x + (x - y) * c[3], c[1] * y + (x - y) * c[2], c[2] * x + c[6] * y}); } } else if (x <= 0 and y <= 0) { x *= -1; y *= -1; if (x <= y) { ans = min({ans, c[4] * x + (y - x) * c[3], c[4] * y + (y - x) * c[2], c[5] * x + c[3] * y}); } else { ans = min({ans, c[4] * x + (x - y) * c[6], c[4] * y + (x - y) * c[5], c[5] * x + c[3] * y}); } } else { x = isnegx * abs(x); y = isnegy * abs(y); if (x <= 0) { x *= -1; ans = min({ans, c[1] * x + (x + y) * c[3], c[4] * y + (x + y) * c[2], c[2] * x + c[3] * y}); } else { y *= -1; ans = min({ans, c[4] * x + (x + y) * c[6], c[1] * y + (x + y) * c[5], c[5] * x + c[6] * y}); } } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int T; cin >> T; while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; long long c[10]; int main() { int t; cin >> t; long long ans; while (t--) { long long x, y; cin >> x >> y; for (int i = 1; i <= 6; i++) cin >> c[i]; c[0] = c[6]; c[7] = c[1]; for (int i = 1; i <= 6; i++) { c[i] = min(c[i], c[i - 1] + c[i + 1]); } if (x >= 0 && y >= 0) { if (x > y) ans = y * c[1] + (x - y) * c[6]; else ans = x * c[1] + (y - x) * c[2]; } else if (x <= 0 && y <= 0) { x = -x, y = -y; if (x > y) ans = y * c[4] + (x - y) * c[3]; else ans = x * c[4] + (y - x) * c[5]; } else if (x > 0) { y = -y; ans = x * c[6] + y * c[5]; } else { x = -x; ans = x * c[3] + y * c[2]; } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { long long x, y; cin >> x >> y; vector<long long> c(6); for (int i = 0; i < 6; i++) cin >> c[i]; vector<long long> b(6); for (int i = 1; i <= 6; i++) { b[i % 6] = min(c[i % 6], c[(i - 1) % 6] + c[(i + 1) % 6]); } long long result = 0; if (x >= 0 && y >= 0) { if (x > y) result = y * b[0] + (x - y) * b[5]; else result = x * b[0] + (y - x) * b[1]; } else if (x >= 0 && y <= 0) { result = x * b[5] - y * b[4]; } else if (x <= 0 && y >= 0) { result = -x * b[2] + y * b[1]; } else { if (x < y) result = -y * b[3] + (y - x) * b[2]; else result = -x * b[3] + (x - y) * b[4]; } cout << result << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; void ritikio(); const long long int inff = LLONG_MAX; const long long int minff = LLONG_MIN; const long long int inf = 1e18; const long long int pmod = 998244353; const long long int mod = 1e9 + 7; const long long int maxm = 2e6 + 3; const long long int maxN = 1e5 + 3; long long int T = 0; void solve() { long long int x, y; cin >> x >> y; long long int c1, c2, c3, c4, c5, c6; cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6; long long int l, r, u, d, ru, lu, rd, ld; u = min((long long int)c2, (long long int)c1 + c3); d = min((long long int)c5, (long long int)c4 + c6); l = min((long long int)c3, (long long int)c4 + c2); r = min((long long int)c6, (long long int)c1 + c5); ru = min((long long int)r + u, (long long int)c1); ld = min((long long int)l + d, (long long int)c4); lu = min((long long int)min((long long int)l + u, (long long int)2 * u + c4), (long long int)2 * l + c1); rd = min((long long int)min((long long int)r + d, (long long int)2 * r + c4), (long long int)2 * d + c1); long long int a, b, ab; if (x >= 0 && y >= 0) a = r, b = u, ab = ru; else if (x <= 0 && y >= 0) a = l, b = u, ab = lu; else if (x <= 0 && y <= 0) a = l, b = d, ab = ld; else if (x >= 0 && y <= 0) a = r, b = d, ab = rd; x = abs(x); y = abs(y); long long int ans = 0; long long int mn = min((long long int)x, (long long int)y); ans += mn * ab; x -= mn, y -= mn; ans += x * a; ans += y * b; cout << ans << endl; } signed main() { ritikio(); long long int TT = 1; T = 0; cin >> TT; while (++T < TT + 1) { ; solve(); } } void ritikio() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, N = 2e2 + 10; long long c[8]; int main() { int t; cin >> t; while (t--) { long long x, y; scanf("%lld%lld", &x, &y); for (int i = 1; i <= 6; i++) { scanf("%lld", &c[i]); } for (int i = 1; i <= 6; i++) { c[2] = min(c[2], c[1] + c[3]); c[6] = min(c[6], c[1] + c[5]); c[3] = min(c[3], c[2] + c[4]); c[1] = min(c[1], c[2] + c[6]); c[4] = min(c[4], c[3] + c[5]); c[5] = min(c[5], c[4] + c[6]); } long long ans; if (x >= 0 && y >= 0) { if (x > y) { ans = y * c[1] + (x - y) * c[6]; } else { ans = x * c[1] + (y - x) * c[2]; } } else if (x >= 0 && y < 0) { ans = -y * c[5] + c[6] * x; } else if (x < 0 && y >= 0) { ans = -x * c[3] + y * c[2]; } else { if (x >= y) ans = c[4] * -x + (x - y) * c[5]; else ans = c[4] * -y + c[3] * (y - x); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { int x, y; cin >> x >> y; array<int64_t, 7> cost; for (int i = 1; i <= 6; ++i) { cin >> cost[i]; } auto path_cost = [&](int64_t x, int64_t plus, int64_t minus) -> int64_t { return (x >= 0 ? plus : -minus) * x; }; int64_t best = numeric_limits<int64_t>::max(); best = min(best, path_cost(x, cost[6], cost[3]) + path_cost(y, cost[2], cost[5])); best = min(best, path_cost(y, cost[1], cost[4]) + path_cost(x - y, cost[6], cost[3])); best = min(best, path_cost(x, cost[1], cost[4]) + path_cost(y - x, cost[2], cost[5])); cout << best << '\n'; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.precision(10); std::cout << std::fixed << std::boolalpha; int t = 1; std::cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long int powm(long long int a, long long int b) { long long int res = 1; while (b) { if (b & 1) res = (res * 1LL * a) % mod; b >>= 1LL; a = (a * 1LL * a) % mod; } return res; } const int N = 2e5 + 5; const int M = 1005; long long int abss(long long int val) { if (val >= 0) return val; return -1LL * val; } void solve() { long long int x, y; cin >> x >> y; long long int c[10]; for (int i = 1; i <= 6; i++) cin >> c[i]; long long int ans = 0; if (x >= 0) { if (y >= 0) { long long int case1 = x * c[6] + y * c[2]; long long int cross = min(x, y); long long int curr = min(x, y); long long int case2 = (cross * c[1] + (x - curr) * c[6] + (y - curr) * c[2]); curr = max(x, y); cross = max(x, y); long long int case3 = (cross * c[1] + abss(x - curr) * c[3] + abss(y - curr) * c[5]); ans = min({case2, case1, case3}); } else { long long int case1 = x * c[6] + abss(y * c[5]); long long int case2 = abss(y * (c[4] + c[6])) + x * c[6]; long long int case3 = x * (c[1] + c[5]) + abss(y * c[5]); ans = min({case3, case2, case1}); } } else { if (y <= 0) { long long int case1 = abss(x * c[3]) + abss(y * c[5]); long long int cross = max(x, y); long long int curr = max(x, y); long long int case2 = abss(cross * c[4]) + abss((x - curr) * c[3]) + abss((y - curr) * c[5]); cross = min(x, y); curr = min(x, y); long long int case3 = abss(cross * c[4]) + abss((x - curr) * c[6]) + abss((y - curr) * c[2]); ans = min({case3, case2, case1}); } else { long long int case1 = abss(x * c[3]) + abss(y * c[2]); long long int case2 = abss(x * (c[4] + c[2])) + abss(y * c[2]); long long int case3 = abss(y * (c[1] + c[3])) + abss(x * c[3]); ans = min({case3, case2, case1}); } } cout << ans << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); int tc = 1; cin >> tc; int _ = 0; while (_++ < tc) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100005; inline int in() { int x; scanf("%d", &x); return x; } inline long long lin() { long long x; scanf("%I64d", &x); return x; } long long n, a, b; int main() { n = lin(); a = 1ll * 1e18; b = 1ll * -1e18; for (long long p = 1; p <= 35000; p++) { if (p > n) continue; if (n % p == 0) { long long aa = p, bb = n / p; for (long long q = 1; q * q <= bb; q++) { if (bb % q == 0) { long long x = q, y = bb / q; a = min(a, (aa + 1ll) * (x + 2ll) * (y + 2ll)); b = max(b, (aa + 1ll) * (x + 2ll) * (y + 2ll)); } } for (long long q = 1; q * q <= aa; q++) { if (aa % q == 0) { long long x = q, y = aa / q; a = min(a, (bb + 1ll) * (x + 2ll) * (y + 2ll)); b = max(b, (bb + 1ll) * (x + 2ll) * (y + 2ll)); } } } } cout << a - n << " " << b - n << '\n'; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, j, i, k, l; cin >> n; for (i = 0; i <= n; i++) { if (i * i * i > n) break; } long long cb = i - 1, sq = sqrt(n), maxi = 0, mini = 1000000000000000000; for (i = 1; i <= cb; i++) { for (j = i; j <= sqrt(n / i); j++) { k = n / (i * j); if (n == i * j * k) { maxi = max(maxi, (i + 1) * (j + 2) * (k + 2) - i * j * k); maxi = max(maxi, (j + 1) * (i + 2) * (k + 2) - i * j * k); maxi = max(maxi, (j + 2) * (i + 2) * (k + 1) - i * j * k); mini = min(mini, (i + 1) * (j + 2) * (k + 2) - i * j * k); mini = min(mini, (j + 1) * (i + 2) * (k + 2) - i * j * k); mini = min(mini, (j + 2) * (i + 2) * (k + 1) - i * j * k); } } } cout << mini << " " << maxi << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; long long mn = 1e18, mx; int main() { cin >> n; long long a; for (long long a = 1; a * a * a <= n; a++) { if (n % a == 0) for (long long b = a; b * b <= n; b++) { long long c; if ((n / a) % b == 0) { long long c = n / a / b; mn = min(mn, (a + 1) * (b + 2) * (c + 2) - n); mn = min(mn, (b + 1) * (c + 2) * (a + 2) - n); mn = min(mn, (c + 1) * (a + 2) * (b + 2) - n); mx = max(mx, (a + 1) * (b + 2) * (c + 2) - n); mx = max(mx, (b + 1) * (c + 2) * (a + 2) - n); mx = max(mx, (c + 1) * (a + 2) * (b + 2) - n); } } } cout << mn << " " << mx; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a, b, c; cin >> n; long long int min1 = pow(10, 28); long long int max1 = 0, t1, t2; for (long long int a = 1; a * a * a <= n; ++a) { if (n % a == 0) { for (long long int b = a; b * b <= n / a; ++b) { if ((n / a) % b == 0) { long long int c = (n / a) / b; t1 = (a + 1) * (b + 2) * (c + 2); max1 = max(max1, t1 - n); min1 = min(min1, t1 - n); t1 = (b + 1) * (a + 2) * (c + 2); max1 = max(max1, t1 - n); min1 = min(min1, t1 - n); t1 = (c + 1) * (a + 2) * (b + 2); max1 = max(max1, t1 - n); min1 = min(min1, t1 - n); } } } } cout << min1 << " " << max1; return 0; }
#include <bits/stdc++.h> using namespace std; vector<long long> maq; void make_maq(long long n) { maq.resize(0); long long i; for (i = 1; i * i < n; i++) if (n % i == 0) { maq.push_back(i); maq.push_back(n / i); } if (i * i == n) maq.push_back(i); return; } int main() { long long n; cin >> n; make_maq(n); long long Min = (-1), Max = (-1); for (int i = 0; i < maq.size(); i++) for (int j = 0; j < maq.size(); j++) if (n % (maq[i] * maq[j]) == 0) { long long A = maq[i] + 1; long long B = maq[j] + 2; long long C = (n / (maq[i] * maq[j])) + 2; if (Min == (-1)) Min = A * B * C; if (Max == (-1)) Max = A * B * C; if (Min > A * B * C) Min = A * B * C; if (Max < A * B * C) Max = A * B * C; } Min -= n; Max -= n; cout << Min << " " << Max << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long max = 0, min = 10e17; for (long long A = 1; A * A <= n; ++A) { if (n % A == 0) { long long a = A; for (long long b = 1; b * b <= n / a; ++b) { if ((n / a) % b == 0) { long long c = n / a / b; long long res = (a + 1) * (b + 2) * (c + 2) - a * b * c; if (res > max) max = res; if (res < min) min = res; } } a = n / A; for (long long b = 1; b * b <= n / a; ++b) { if ((n / a) % b == 0) { long long c = n / a / b; long long res = (a + 1) * (b + 2) * (c + 2) - a * b * c; if (res > max) max = res; if (res < min) min = res; } } } } cout << min << ' ' << max; return 0; }
#include <bits/stdc++.h> using namespace std; long long a, b, c, n, i, j, res1 = 1e12, res2 = -1e12; vector<long long> d; int main() { cin >> n; for (i = 1; i * i <= n; i++) if (n % i == 0) { d.push_back(i); if (n / i != i) d.push_back(n / i); } for (i = 0; i < d.size(); i++) for (j = 0; j < d.size(); j++) { a = d[i]; b = d[j]; if (n % (a * b) == 0) { c = n / (a * b); res1 = min(res1, (a + 1) * (b + 2) * (c + 2)); res2 = max(res2, (a + 1) * (b + 2) * (c + 2)); } } cout << res1 - n << " " << res2 - n << endl; }
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { return (a > b ? a : b); } long long min(long long a, long long b) { return (a > b ? b : a); } int da[] = {0, 1, 2, 2}; int db[] = {0, 2, 1, 2}; int dc[] = {0, 2, 2, 1}; int main() { long long n; scanf("%I64d", &n); long long Min = (1LL << 60), Max = 9 * n + 9; for (long long a = 1000; a >= 1; a--) { if (n % a == 0) { long long h = n / a; long long k = sqrt(h); for (int b = k + 2; b >= 1; b--) { if (h % b == 0) { long long c = h / b; for (int i = 1; i <= 3; i++) { Min = min(Min, (a + da[i]) * (b + db[i]) * (c + dc[i])); } } } } } printf("%I64d %I64d\n", Min - n, Max - n); return 0; }
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } clock_t time_p = clock(); void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)1000 * (time_p) / CLOCKS_PER_SEC << "\n"; } const long long INF = 1e15; const long long MOD = 1e9 + 7; const long long N = 2e5 + 10; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t = 1; long long tc = 1; while (t--) { long long n; cin >> n; long long mn = INF, mx = 0; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { long long f = i; long long s = n / i; for (long long j = 1; j * j <= f; j++) { if (f % j == 0) { long long v1 = j, v2 = f / j, v3 = s; long long val1 = (v1 + 1) * (v2 + 2) * (v3 + 2); long long val2 = (v2 + 1) * (v3 + 2) * (v1 + 2); long long val3 = (v3 + 1) * (v1 + 2) * (v2 + 2); long long l1 = val1 - n; long long l2 = val2 - n; long long l3 = val3 - n; mn = min({mn, l1, l2, l3}); mx = max({mx, l1, l2, l2}); } } for (long long j = 1; j * j <= s; j++) { if (s % j == 0) { long long v1 = j, v2 = s / j, v3 = f; long long val1 = (v1 + 1) * (v2 + 2) * (v3 + 2); long long val2 = (v2 + 1) * (v3 + 2) * (v1 + 2); long long val3 = (v3 + 1) * (v1 + 2) * (v2 + 2); long long l1 = val1 - n; long long l2 = val2 - n; long long l3 = val3 - n; mn = min({mn, l1, l2, l3}); mx = max({mx, l1, l2, l2}); } } } } cout << mn << " " << mx << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; long long dd(long long x, long long y) { return x > y ? x : y; } long long xx(long long x, long long y) { return x < y ? x : y; } int main() { long long n, q, w; long long mks = 0, mii = 1e18; cin >> n; int a, b, c, i, j; for (i = 1; i <= (int)sqrt(n) + 1; i++) { if (n % i == 0) { q = n / i; for (j = 1; j <= (int)sqrt(q) + 1; j++) { if (q % j == 0) { w = q / j; mks = dd(mks, (long long)(i + 1) * (j + 2) * (w + 2)); mks = dd(mks, (long long)(i + 2) * (j + 1) * (w + 2)); mks = dd(mks, (long long)(i + 2) * (j + 2) * (w + 1)); mii = xx(mii, (long long)(i + 1) * (j + 2) * (w + 2)); mii = xx(mii, (long long)(i + 2) * (j + 1) * (w + 2)); mii = xx(mii, (long long)(i + 2) * (j + 2) * (w + 1)); } } } } mks -= n; mii -= n; cout << mii << " " << mks; }
#include <bits/stdc++.h> using namespace std; long long n, ans1, ans2; vector<long long> v; int main() { cin >> n; ans2 = 1000000000; ans2 *= ans2; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { v.push_back(i); v.push_back(n / i); } } for (long long j = 0; j < v.size(); j++) { long long t = n / v[j]; for (long long q = 1; q * q <= t; q++) if (t % q == 0) { ans1 = max(ans1, (v[j] + 1) * (q + 2) * (t / q + 2) - (v[j]) * (q) * (t / q)); ans2 = min(ans2, (v[j] + 1) * (q + 2) * (t / q + 2) - (v[j]) * (q) * (t / q)); } } cout << ans2 << " " << ans1 << endl; cin.get(); cin.get(); return 0; }
#include <bits/stdc++.h> using namespace std; const long long inf = 2e18 + 100; long long n, a, b, c; signed main() { cin >> n; long long ans = inf; for (a = 1; a <= sqrt(n); a++) { if (n % a != 0) continue; for (b = 1; b <= sqrt(n / a); b++) { if (n % (a * b) == 0) { c = n / (a * b); ans = min(ans, (a + 1) * (b + 2) * (c + 2) - n); ans = min(ans, (a + 2) * (b + 1) * (c + 2) - n); ans = min(ans, (a + 2) * (b + 2) * (c + 1) - n); } } } cout << ans << " "; cout << (n + 1) * 3 * 3 - n << "\n"; }
#include <bits/stdc++.h> using namespace std; class Myfirst { private: string *name; long long int *age; public: long long int gcd(long long int a, long long int b) { if (b == 0) return a; a %= b; return gcd(b, a); } long long int exte_gcd(long long int a, long long int b, long long int &x, long long int &y) { if (b == 0) { x = 1; y = 0; return a; } long long int x1, y1; long long int d = exte_gcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b); return d; } long long int powe(long long int d, long long int s) { if (s == 1) return d; else if (s == 0) return 1; else { long long int u, v = d; for (u = 1; u < s; u++) d = d * v; return d; } } long long int count_divisors(long long int b) { long long int i, count = 0, n = 1; for (i = 2; i * i <= b; i++) { count = 0; if (b % i == 0) { while (b % i == 0) { b = b / i; count++; } n = n * (count + 1); } } if (b > 1) n = 2 * n; return n; } long long int bigmod(long long int a, long long int b, long long int mod) { if (b == 0) return 1; long long int x = bigmod(a, b / 2, mod); x = (x * x) % mod; if (b % 2) x = (x * a) % mod; return x; } long long int phi(long long int n) { double result = n; for (long long int p = 2; p * p <= n; ++p) { if (n % p == 0) { while (n % p == 0) n /= p; result *= (1.0 - (1.0 / (double)p)); } } if (n > 1) result *= (1.0 - (1.0 / (double)n)); return (long long int)result; } void solve() { long long int t; t = 1; while (t--) { long long int n, i, x, mn = 1e18, j; cin >> n; long long int mx = (n + 1) * 9 - n; for (i = 1; i * i <= n; i++) { long long int ans2, ans3, ans; if (n % i == 0) { ans = i; x = n / i; for (j = 1; j * j <= x; j++) { if (x % j == 0) { ans2 = j; ans3 = x / j; } long long int a[3]; a[0] = ans; a[1] = ans2, a[2] = ans3; sort(a, a + 3); mn = min(mn, ((1 + a[0]) * (2 + a[1]) * (2 + a[2]) - n)); } } } cout << mn << " " << mx; } } }; int main() { Myfirst *prg = new Myfirst(); prg->solve(); }
#include <bits/stdc++.h> using namespace std; long long res_min = (long long)1E18; long long res_max = (long long)0; int n; void process_c(int b, int c) { int a = n / b / c; long long v = (long long)(a + 1) * (long long)(b + 2) * (long long)(c + 2) - n; if (v > 0) { res_min = min(v, res_min); res_max = max(v, res_max); } } void process_b(int b) { int d = n / b; for (int i = 1; i * i <= d; i++) { if (d % i == 0) { process_c(b, i); process_c(b, d / i); } } } int main() { cin >> n; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { process_b(i); process_b(n / i); } } cout << res_min << " " << res_max << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, -1, 1}; int n; long long Min, Max; int main() { cin >> n; Min = 1 << 31; Min *= Min; for (int i = 1; i * i <= n; ++i) if (n % i == 0) for (int j = i; j * j <= n / i; ++j) if (n / i % j == 0) { int k = n / i / j; if (k < j) break; long long a = i, b = j, c = k; Min = min(Min, (a + 1) * (b + 2) * (c + 2)); Max = max(Max, (c + 1) * (a + 2) * (b + 2)); } cout << Min - n << " " << Max - n << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; long long ans1 = LONG_LONG_MAX; long long ans2 = LONG_LONG_MIN; cin >> n; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { for (long long j = 1; j * j <= n / i; j++) { if ((n / i) % j == 0) { long long k = n / i / j; ans1 = min(ans1, -i * j * k + (i + 1) * (j + 2) * (k + 2)); ans2 = max(ans2, -i * j * k + (i + 1) * (j + 2) * (k + 2)); } } for (long long j = 1; j * j <= i; j++) { if (i % j == 0) { long long k = i / j; ans1 = min(ans1, -n / i * j * k + (n / i + 1) * (j + 2) * (k + 2)); ans2 = max(ans2, -n / i * j * k + (n / i + 1) * (j + 2) * (k + 2)); } } } } cout << ans1 << ' ' << ans2 << endl; }
#include <bits/stdc++.h> using namespace std; long long i, j, m, n, s, t, x, y, z, k, ma, mi; int main() { while (scanf("%lld", &n) != EOF) { ma = 0; mi = n * 1000; t = sqrt(n); for (i = 1; i <= t; i++) { if (n % i == 0) { k = sqrt(i); for (j = 1; j <= k + 1; j++) { if (i % j == 0) { x = i / j; y = j; z = n / i; if (((x + 1) * (y + 2) * (z + 2) - n) < mi) mi = (x + 1) * (y + 2) * (z + 2) - n; if (((x + 1) * (y + 2) * (z + 2) - n) > ma) ma = (x + 1) * (y + 2) * (z + 2) - n; x = j; y = i / j; z = n / i; if (((x + 1) * (y + 2) * (z + 2) - n) < mi) mi = (x + 1) * (y + 2) * (z + 2) - n; if (((x + 1) * (y + 2) * (z + 2) - n) > ma) ma = (x + 1) * (y + 2) * (z + 2) - n; x = n / i; j = y; z = i / j; if (((x + 1) * (y + 2) * (z + 2) - n) < mi) mi = (x + 1) * (y + 2) * (z + 2) - n; if (((x + 1) * (y + 2) * (z + 2) - n) > ma) ma = (x + 1) * (y + 2) * (z + 2) - n; } } k = sqrt(n / i); m = n / i; for (j = 1; j <= k; j++) { if (n / i % j == 0) { x = i; y = j; z = (n / i) / j; if (((x + 1) * (y + 2) * (z + 2) - n) < mi) mi = (x + 1) * (y + 2) * (z + 2) - n; if (((x + 1) * (y + 2) * (z + 2) - n) > ma) ma = (x + 1) * (y + 2) * (z + 2) - n; x = j; y = i; z = n / i / j; if (((x + 1) * (y + 2) * (z + 2) - n) < mi) mi = (x + 1) * (y + 2) * (z + 2) - n; if (((x + 1) * (y + 2) * (z + 2) - n) > ma) ma = (x + 1) * (y + 2) * (z + 2) - n; x = n / i / j; y = j; z = i; if (((x + 1) * (y + 2) * (z + 2) - n) < mi) mi = (x + 1) * (y + 2) * (z + 2) - n; if (((x + 1) * (y + 2) * (z + 2) - n) > ma) ma = (x + 1) * (y + 2) * (z + 2) - n; } } } } printf("%lld %lld\n", mi, ma); } }
#include <bits/stdc++.h> using namespace std; int main() { int i, j; long long mn = -1, mx = -1, n; vector<long long> v; cin >> n; v.push_back(1); v.push_back(n); for (i = 2; i * i <= n; i++) { if (n % i == 0) { v.push_back(i); v.push_back(n / i); } } sort(v.begin(), v.end()); for (i = 0; i < v.size(); i++) { for (j = i + 1; j < v.size(); j++) { if ((n / v[i]) % v[j] == 0) { if (mn == -1) mn = (v[i] + 1) * (v[j] + 2) * ((n / v[i]) / v[j] + 2); mn = min(mn, (v[i] + 1) * (v[j] + 2) * ((n / v[i]) / v[j] + 2)); mn = min(mn, (v[i] + 2) * (v[j] + 1) * ((n / v[i]) / v[j] + 2)); mn = min(mn, (v[i] + 2) * (v[j] + 2) * ((n / v[i]) / v[j] + 1)); mx = max(mx, (v[i] + 1) * (v[j] + 2) * ((n / v[i]) / v[j] + 2)); mx = max(mx, (v[i] + 2) * (v[j] + 1) * ((n / v[i]) / v[j] + 2)); mx = max(mx, (v[i] + 2) * (v[j] + 2) * ((n / v[i]) / v[j] + 1)); } } } cout << mn - n << " " << mx - n; return 0; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b > 0 ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } inline long long read() { long long X = 0; bool flag = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') flag = 0; ch = getchar(); } while (ch >= '0' && ch <= '9') { X = (X << 1) + (X << 3) + ch - '0'; ch = getchar(); } if (flag) return X; return ~(X - 1); } mt19937 rnd(time(0)); int main() { long long n; cin >> n; long long ma, mi = (long long)1e16; ma = 3 * 3 * (n + 1) - n; for (long long i = floor(pow(n, 1.0 / 3.0)); i >= 1; i--) { if (n % i == 0) { for (long long j = floor(sqrt(n)); j >= 1; j--) { if ((n / i) % j == 0) mi = min(mi, (i + 1) * (j + 2) * (n / i / j + 2) - n); } } } cout << mi << " " << ma << "\n"; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAX = 100010; int main() { ios_base::sync_with_stdio(0); long long int n; cin >> n; long long int mi = 1LL << 40, ma = 0; for (long long int a = 1; a * a * a <= n; a++) { if (n % a == 0) { for (long long int b = 1; b * b <= n / a; b++) { if ((n / a) % b == 0) { long long int c = n / a / b; long long int v1 = (a + 1) * (b + 2) * (c + 2) - n; long long int v2 = (a + 2) * (b + 2) * (c + 1) - n; long long int v3 = (a + 2) * (b + 1) * (c + 2) - n; mi = min(mi, v1); mi = min(mi, v2); mi = min(mi, v3); ma = max(ma, v1); ma = max(ma, v2); ma = max(ma, v2); } } } } cout << mi << " " << ma << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int const MAX = 10; int const OO = (1 << 28); int main() { long long N; cin >> N; long long mx = -1, mn = (1LL << 62); for (long long i = 1; (i * i) <= N; ++i) { if (N % i) continue; long long n = N / i; for (long long j = 1; (j * j) <= n; ++j) { if (n % j) continue; long long A = i, B = j, C = n / j; mn = min(mn, ((A + 1) * (B + 2) * (C + 2)) - N); mn = min(mn, ((B + 1) * (A + 2) * (C + 2)) - N); mn = min(mn, ((C + 1) * (A + 2) * (B + 2)) - N); mx = max(mx, ((A + 1) * (B + 2) * (C + 2)) - N); mx = max(mx, ((B + 1) * (A + 2) * (C + 2)) - N); mx = max(mx, ((C + 1) * (B + 2) * (A + 2)) - N); } } cout << mn << " " << mx << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, n, aux, sq; int x; scanf("%d", &x); n = x; long long menor = 999999999999999LL, maior = 0; long long ate = sqrt(n) + 1; for (a = 1; a <= ate; a++) { if (n % a != 0) continue; sq = sqrt(n / a) + 1; for (b = 1; b <= sq; ++b) { if (n % (a * b) != 0) continue; c = n / (a * b); aux = b * c + (a + 1) * c * 2 + ((a + 1) * (b + 2) << 1); if (aux < menor) menor = aux; if (aux > maior) maior = aux; } b = n / a; if (n % (a * b) != 0) continue; c = n / (a * b); aux = b * c + (a + 1) * c * 2 + ((a + 1) * (b + 2) << 1); if (aux < menor) menor = aux; if (aux > maior) maior = aux; } a = n; b = 1; c = 1; aux = b * c + (a + 1) * c * 2 + ((a + 1) * (b + 2) << 1); if (aux < menor) menor = aux; if (aux > maior) maior = aux; printf("%I64d %I64d\n", menor, maior); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a, b, c; cin >> n; long long int min1 = pow(10, 28); long long int max1 = 0, t1, t2; for (long long int a = 1; a * a * a <= n; ++a) { if (n % a == 0) { for (long long int b = a; b * b <= n / a; ++b) { if ((n / a) % b == 0) { long long int c = (n / a) / b; t1 = (a + 1) * (b + 2) * (c + 2); if (t1 >= 18 && a >= 1 && b >= 1 && c >= 1) { max1 = max(max1, t1 - n); min1 = min(min1, t1 - n); } t1 = (b + 1) * (a + 2) * (c + 2); if (t1 >= 18 && a >= 1 && b >= 1 && c >= 1) { max1 = max(max1, t1 - n); min1 = min(min1, t1 - n); } t1 = (c + 1) * (a + 2) * (b + 2); if (t1 >= 18 && a >= 1 && b >= 1 && c >= 1) { max1 = max(max1, t1 - n); min1 = min(min1, t1 - n); } } } } } cout << min1 << " " << max1; return 0; }
#include <bits/stdc++.h> using ll = long long; int main() { ll n; std::cin >> n; std::vector<ll> div; for (ll x = 1; x * x <= n; x++) { if (n % x == 0) { div.push_back(x); if (n / x != x) { div.push_back(n / x); } } } ll ma = -1, mi = 1e18; for (int i = 0; i < div.size(); i++) { for (int j = 0; j < div.size(); j++) { ll a = div[i] + 1, b = div[j] + 2; ll tmp = (a - 1) * (b - 2); if (n % tmp != 0) continue; ll c = n / tmp + 2; ma = std::max(ma, a * b * c); mi = std::min(mi, a * b * c); } } std::cout << mi - n << " " << ma - n << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n; cin >> n; long long minblocks = LLONG_MAX; long long maxblocks = LLONG_MIN; for (long long i = 1; i * i * i <= n; i++) { if (n % i == 0) { for (long long j = i; j * j <= n / i; j++) { if ((n / i) % j == 0) { long long k = n / i; k /= j; long long x = (i + 1) * (j + 2) * (k + 2); long long y = (j + 1) * (i + 2) * (k + 2); long long z = (k + 1) * (j + 2) * (i + 2); minblocks = min(minblocks, x - n); minblocks = min(minblocks, y - n); minblocks = min(minblocks, z - n); maxblocks = max(maxblocks, x - n); maxblocks = max(maxblocks, y - n); maxblocks = max(maxblocks, z - n); } } } } cout << minblocks << " " << maxblocks; }
#include <bits/stdc++.h> int main() { long long n, a, b, c, i, j, k, diff, min = 10000000000, max; scanf("%lld", &n); for (i = 1; i * i * i <= n; i++) { if (n % i == 0) { for (j = i; j * j <= n / i; j++) { if (n % j == 0) k = n / (i * j); a = i + 1; b = j + 2; c = k + 2; if ((a - 1) * (b - 2) * (c - 2) == n) diff = (a * b * c) - n; if (min > diff) min = diff; } } } max = 9 * (n + 1) - n; printf("%lld %lld", min, max); return 0; }
#include <bits/stdc++.h> using namespace std; const long long int inf = 0x3f3f3f3f3f3f; int main() { long long int n; cin >> n; long long int mx = (n + 1) * 3 * 3 - n; long long int a, b, c, mn = inf; for (long long int a = 1; a * a * a <= n; a++) { if (n % a == 0) { for (long long int b = a; b * b <= n / a; b++) { if ((n / a) % b == 0) { c = (n / a) / b; mn = min(mn, (a + 1) * (b + 2) * (c + 2) - n); } } } } cout << mn << " " << mx << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long mi = -1, ma = -1, n, m; cin >> n; ma = (n + 1) * 3 * 3; m = (long long)sqrt(n); for (long long i = 1; i <= m; ++i) { if (n % i == 0) { long long t = (i + 2) * (n / i + 2) * 2; ma = max(ma, t); if (mi == -1 || mi > t) mi = t; t = n / i; long long k = (long long)sqrt(t); for (long long j = 1; j <= k; ++j) { if (t % j == 0) { mi = min(mi, (i + 1) * (j + 2) * (t / j + 2)); mi = min(mi, (i + 2) * (j + 1) * (t / j + 2)); mi = min(mi, (t / j + 1) * (i + 2) * (j + 2)); ma = max(ma, (i + 1) * (j + 2) * (t / j + 2)); ma = max(ma, (i + 2) * (j + 1) * (t / j + 2)); ma = max(ma, (i + 2) * (j + 2) * (t / j + 1)); } } } } cout << (mi - n) << " " << (ma - n) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int _n, n, ql, qq[30], sum[30]; long long _a, _b, _c, _min, _max, tmp; void Dfs(int u, int deta) { if (u > ql) { _n = n / deta; _a = deta + 1; _b = 3; _c = _n + 2; tmp = _a * _b * _c; if (tmp > _max) _max = tmp; for (int i = int(sqrt(_n + 1)); i; --i) if ((_n % i) == 0) { _b = i + 2; _c = (_n / i) + 2; break; } tmp = _a * _b * _c; if (tmp < _min) _min = tmp; return; } Dfs(u + 1, deta); for (int i = 1; i <= sum[u]; ++i) { deta *= qq[u]; Dfs(u + 1, deta); } } int main() { scanf("%d", &n); int _m = int(sqrt(n + 1)), m = n; ql = 0; for (int i = 2; i <= _m; ++i) { if (m % i) continue; ++ql; qq[ql] = i; sum[ql] = 1; m /= i; for (; (m % i) == 0; m /= i) ++sum[ql]; } if (m > 1) { ++ql; qq[ql] = m; sum[ql] = 1; } _max = -1; _min = 1000000000; _min *= 10000000; Dfs(1, 1); cout << (_min - n) << " " << (_max - n) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long inf = 2e18 + 100; long long n, a, b, c; signed main() { cin >> n; long long ans = inf; for (a = 1; a <= sqrt(n); a++) { if (n % a != 0) continue; for (b = 1; b <= sqrt(n); b++) { if (n % (a * b) == 0) { c = n / (a * b); ans = min(ans, (a + 1) * (b + 2) * (c + 2) - n); ans = min(ans, (a + 2) * (b + 1) * (c + 2) - n); ans = min(ans, (a + 2) * (b + 2) * (c + 1) - n); } } } cout << ans << " "; cout << (n + 1) * 3 * 3 - n << "\n"; }
#include <bits/stdc++.h> using namespace std; long long min(long long a, long long b) { if (a > b) return b; return a; } long long max(long long a, long long b) { if (a > b) return a; return b; } long long fact[32600]; int main() { int n, len, l; cin >> n; len = (int)(sqrt(n)); l = 0; for (int i = 1; i <= len; ++i) { if (n % i == 0) { fact[l++] = i; if (i != n / i) fact[l++] = n / i; } } sort(fact, fact + l); long long mini = 1LL << 63 - 1, maxi = 0LL; for (int i = 0; i < l; ++i) { for (int j = i; j < l; ++j) { for (int k = j; k < l; ++k) { long long aux = fact[i] * fact[j] * fact[k]; if (aux == n) { long long another = (fact[i] + 1) * (fact[j] + 2) * (fact[k] + 2) - n; long long other = (fact[k] + 1) * (fact[j] + 2) * (fact[i] + 2) - n; mini = min(another, min(other, mini)); maxi = max(another, max(other, maxi)); another = (fact[j] + 1) * (fact[i] + 2) * (fact[k] + 2) - n; other = (fact[i] + 1) * (fact[j] + 2) * (fact[k] + 2) - n; another = (fact[k] + 1) * (fact[i] + 2) * (fact[j] + 2) - n; other = (fact[j] + 1) * (fact[i] + 2) * (fact[k] + 2) - n; mini = min(another, min(other, mini)); maxi = max(another, max(other, maxi)); } } } } cout << mini << " " << maxi << endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> v; int main() { int n; scanf("%d", &n); long long min_x = (~(1LL << 63)), max_x = -1; long long i = 1; for (; i * i < n; ++i) if (n % i == 0) v.emplace_back(i), v.emplace_back(n / i); if (n % i == 0) v.emplace_back(n); int b, c, m; for (const auto &a : v) { m = n / a; i = 1; for (; i * i <= m; ++i) if (m % i == 0) { b = i, c = m / i; long long t = 1ll * (a + 1) * (b + 2) * (c + 2) - n; if (t < min_x) min_x = t; if (t > max_x) max_x = t; } } printf("%I64d %I64d", min_x, max_x); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1000000 + 10; const int INF = 1e9 + 7; const int MOD = 1e9 + 7; const double eps = 1e-10; const double pi = acos(-1); long long T, cases, n, m; int main() { ios::sync_with_stdio(false); ; cin >> n; long long tmp = 1e15; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { for (long long j = 1; j * j <= i; j++) { if (i % j == 0) { tmp = min(tmp, (n / i + 1) * (j + 2) * (i / j + 2)); } } for (long long j = 1; j * j <= n / i; j++) { if (n / i % j == 0) { tmp = min(tmp, (i + 1) * (j + 2) * (n / i / j + 2)); } } } } cout << tmp - n << " " << 8LL * n + 9 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int maxx = 0, minx = 1e18; for (long long int i = 1; i <= sqrt(n) + 1; i++) { if (n % i == 0) { long long int p = n / i; for (long long int j = 1; j <= sqrt(p) + 1; j++) { if (p % j == 0) { long long int k = p / j; minx = min(minx, (i + 1) * (j + 2) * (k + 2)); minx = min(minx, (i + 2) * (j + 1) * (k + 2)); minx = min(minx, (i + 2) * (j + 2) * (k + 1)); maxx = max(maxx, (i + 1) * (j + 2) * (k + 2)); maxx = max(maxx, (i + 2) * (j + 1) * (k + 2)); maxx = max(maxx, (i + 2) * (j + 2) * (k + 1)); } } } } cout << minx - n << " " << maxx - n << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long int mod_expo(long long int MOD, long long int a, long long int b) { long long int ans = 1; while (b) { if (b % 2) { ans *= a; ans %= MOD; } b /= 2; a *= a; a %= MOD; } return ans % MOD; } void display(vector<int> v1) { for (int i = 0; i < v1.size(); i++) { cout << v1[i] << " "; } cout << endl; } int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1}; using namespace std; long long int n; void computemin() { long long int ans = (long long int)1e18; for (long long int i = 1; i <= sqrt(n); i += 1) { if (n % i == 0) { long long int firsty = i; long long int second = n / i; for (long long int j = 1; j <= sqrt(second); j += 1) { if (second % j == 0) { long long int newone = (firsty + 1) * (j + 2) * ((second / j) + 2); ans = min(ans, newone - n); } } } } cout << ans << " "; } void computemax() { long long int orig = (n + 1) * 3LL * 3LL; cout << orig - n << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; computemin(); computemax(); return 0; }
#include <bits/stdc++.h> const double EPS = 1e-24; const long long int MOD = 1000000007ll; const double PI = 3.14159265359; int INF = 2147483645; template <class T> T Max2(T a, T b) { return a < b ? b : a; } template <class T> T Min2(T a, T b) { return a < b ? a : b; } template <class T> T Max3(T a, T b, T c) { return Max2(Max2(a, b), c); } template <class T> T Min3(T a, T b, T c) { return Min2(Min2(a, b), c); } template <class T> T Max4(T a, T b, T c, T d) { return Max2(Max2(a, b), Max2(c, d)); } template <class T> T Min4(T a, T b, T c, T d) { return Min2(Min2(a, b), Max2(c, d)); } using namespace std; long long int N; vector<long long int> v; long long int ansmax = -1, ansmin = 1000000000000000000ll; void solve(long long int i, long long int j, long long int k) { if ((i * j * k) < N) return; ansmax = Max2(ansmax, (i + 1) * (j + 2) * (k + 2) - N); ansmin = Min2(ansmin, (i + 1) * (j + 2) * (k + 2) - N); } int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cin >> N; long long int t = sqrt(N); for (long long int i = 1; i <= t; i++) if (N % i == 0) v.push_back(i), v.push_back(N / i); sort(v.begin(), v.end()); for (int i = 0; i < v.size(); i++) for (int j = 0; j < v.size(); j++) solve(v[i], v[j], N / v[i] / v[j]); cout << ansmin << " " << ansmax; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, j, k, res1, ans; long long MIN = 1000000000000; long long MAX = -MIN; cin >> n; for (i = 1; i * i <= n; i++) { if (n % i) continue; res1 = n / i; for (j = 1; j * j <= res1; j++) { if (res1 % j) continue; k = res1 / j; ans = (i + 1) * (j + 2) * (k + 2) - i * j * k; MAX = max(MAX, ans); MIN = min(MIN, ans); ans = (i + 2) * (j + 1) * (k + 2) - i * j * k; MAX = max(MAX, ans); MIN = min(MIN, ans); ans = (i + 2) * (j + 2) * (k + 1) - i * j * k; MAX = max(MAX, ans); MIN = min(MIN, ans); } } cout << MIN << " " << MAX << endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long i, k, j, n, ans1 = 1e18 + 1, ans2 = 0; cin >> n; vector<long long> v; for (i = 1; i <= sqrt(n); i++) { if (n % i == 0) { long long f1 = i, f2 = n / i; if (f1 == f2) v.push_back(f1); else { v.push_back(f1); v.push_back(f2); } } } for (i = 0; i < v.size(); i++) { for (j = 0; j < v.size(); j++) { long long tmp = v[i] * v[j]; if (n % tmp != 0) continue; long long num = n / tmp; long long nn = (v[i] + 1) * (v[j] + 2) * (num + 2); ans1 = min(ans1, nn - n); ans2 = max(ans2, nn - n); } } cout << ans1 << ' ' << ans2; }
#include <bits/stdc++.h> using namespace std; int main() { uint64_t n, a, b, c, i, j, mini, maxi, temp; cin >> n; mini = -1; vector<uint64_t> divisors1; for (i = 1; i * i <= n; i++) { if (n % i == 0) { b = i; temp = n / i; for (j = 1; j * j <= temp; j++) { if (temp % j == 0) { a = j; c = temp / j; } } j = min(a, min(b, c)); maxi = max(max(a, b), c); b = a + b + c - j - maxi; a = j; c = maxi; j = (a + 1) * (b + 2) * (c + 2) - n; if (mini == -1) mini = j; else if (mini > j) mini = j; } } maxi = (n + 1) * 3 * 3 - n; cout << mini << " " << maxi << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-10; const long double infty = 1e+10; void getMinMax(unsigned long long n, unsigned long long& mini, unsigned long long& maxi) { maxi = 0; unsigned long long i, t; for (i = 1; i * i * i <= n; i++) { } for (t = 1; t * t <= n; t++) { } for (unsigned long long j = 1; j <= i; j++) { unsigned long long yo = min(t, n / j); for (unsigned long long k = j; k <= yo; k++) { if (n % (j * k) == 0) { maxi = max(maxi, (j + 1) * (k + 2) * (n / (j * k) + 2)); maxi = max(maxi, (j + 2) * (k + 1) * (n / (j * k) + 2)); maxi = max(maxi, (j + 2) * (k + 2) * (n / (j * k) + 1)); } } } mini = maxi; for (unsigned long long j = 1; j <= i; j++) { unsigned long long yo = min(t, n / j); for (unsigned long long k = j; k <= yo; k++) { if (n % (j * k) == 0) { mini = min(mini, (j + 1) * (k + 2) * (n / (j * k) + 2)); mini = min(mini, (j + 2) * (k + 1) * (n / (j * k) + 2)); mini = min(mini, (j + 2) * (k + 2) * (n / (j * k) + 1)); } } } mini -= n; maxi -= n; } int main() { unsigned long long n; cin >> n; unsigned long long mini, maxi; getMinMax(n, mini, maxi); cout << mini << " " << maxi << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long minAns = 1ll << 60, maxAns = -(1ll << 60); long long value(int a, int b, int c) { return (1ll * a) * (1ll * b) * c - (1ll * (a - 1)) * (1ll * (b - 2)) * (c - 2); } void check(int x, int a) { int lim = int(sqrt(x)) + 4; for (int b = 1; b <= lim; b++) { if (x % b) continue; minAns = min(minAns, value(a + 1, b + 2, x / b + 2)); maxAns = max(maxAns, value(a + 1, b + 2, x / b + 2)); minAns = min(minAns, value(a + 1, x / b + 2, b + 2)); maxAns = max(maxAns, value(a + 1, x / b + 2, b + 2)); } } int main(void) { int n; cin >> n; int lim = int(sqrt(n)) + 4; for (int a = 1; a <= lim; a++) { if (n % a) continue; check(a, n / a); check(n / a, a); } cout << minAns << " " << maxAns; return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1 << 60; long long ansMin = INF, ansMax = -INF; bool shit1 = false, shit2 = false; vector<long long> divisors; vector<long long> temp(3); void defineDivisrors(int N) { for (int i = 1; i * i <= N; i++) { if (N % i == 0) { divisors.push_back(i); if (i * i != N) { divisors.push_back(N / i); } } } sort(divisors.begin(), divisors.end()); } void sol(long long cur) { for (int i = 0; i < divisors.size(); i++) { for (int j = 0; j < divisors.size(); j++) { if (((cur / divisors[i]) / divisors[j]) * divisors[i] * divisors[j] == cur) { long long w = (cur / divisors[i]) / divisors[j]; long long temp = w * divisors[j] * 2 + divisors[i] * w * 2 + divisors[j] * divisors[i] + 4 + 4 * w + 2 * divisors[j] + 2 * divisors[i]; cerr << divisors[i] << ' ' << divisors[j] << ' ' << w << ' ' << temp << '\n'; if (temp != 0 && (!shit1 || ansMin > temp)) { ansMin = temp; shit1 = true; } if (!shit2 || ansMax < temp) { ansMax = temp; shit2 = true; } } } } } int main() { cin.sync_with_stdio(false); cout.sync_with_stdio(false); long long n; cin >> n; defineDivisrors(n); sol(n); cout << ansMin << ' ' << ansMax; return 0; }
#include <bits/stdc++.h> using namespace std; const int INFint = 2147483647; const long long INF = 9223372036854775807ll; const long long MOD = 1000000007ll; const long double EPS = 1e-9; int main() { ios_base::sync_with_stdio(0); long long n; cin >> n; long long ans = INF; long long ans1 = -INF; for (long long a = 1; a * a * a <= n; a++) if (n % a == 0) for (long long b = a; b * b <= n / a; b++) { if ((n / a) % b == 0) { long long c = n / a / b; ans = min(ans, (a + 1) * (b + 2) * (c + 2)); ans1 = max(ans1, (a + 1) * (b + 2) * (c + 2)); ans = min(ans, (a + 2) * (b + 1) * (c + 2)); ans1 = max(ans1, (a + 2) * (b + 1) * (c + 2)); ans = min(ans, (a + 2) * (b + 2) * (c + 1)); ans1 = max(ans1, (a + 2) * (b + 2) * (c + 1)); } } cout << ans - n << ' ' << ans1 - n; fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock() / CLOCKS_PER_SEC); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, n, b, s = 1e18; scanf("%I64d", &n); b = 9ll * (n + 1) - n; for (i = 1; i * i <= n; i++) { if (n % i) continue; for (j = i; j * j <= n / i; j++) { if (n / i % j) continue; s = min(s, (i + 1) * (j + 2) * (n / i / j + 2) - n); } } printf("%I64d %I64d\n", s, b); }
#include <bits/stdc++.h> using namespace std; long long valor(int A, int B, int C, int n) { A = (long long)((long long)A + (long long)1), B = (long long)((long long)B + (long long)2), C = (long long)((long long)C + (long long)2); return (long long)((long long)A * (long long)B * (long long)C - (long long)n); } int main() { int n, A, B, C; long long r, menor, mayor; while (cin >> n) { menor = (long long)(1e15), mayor = -1; for (A = 1; A <= n / A; A++) { if (n % A == 0) { for (B = 1; B <= (n / A) / B; B++) { if ((n / A) % B == 0) { C = (n / A) / B; r = valor(A, B, C, n), menor = min(menor, r), mayor = max(mayor, r); r = valor(A, C, B, n), menor = min(menor, r), mayor = max(mayor, r); r = valor(B, A, C, n), menor = min(menor, r), mayor = max(mayor, r); r = valor(B, C, A, n), menor = min(menor, r), mayor = max(mayor, r); r = valor(C, A, B, n), menor = min(menor, r), mayor = max(mayor, r); r = valor(C, B, A, n), menor = min(menor, r), mayor = max(mayor, r); } } } } cout << menor << " " << mayor << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long A, B, C, n; int main() { long long min, max = 0; min = 1e11; cin >> n; for (int i = 1; i * i * i <= n; ++i) { if (n % i == 0) { for (int j = 1; j * j <= n / i; ++j) { if ((n / i) % j == 0) { A = i + 1; B = j + 2; C = (n / i) / j + 2; if (A * B * C > max) max = A * B * C; if (A * B * C < min) min = A * B * C; A = j + 1; B = i + 2; if (A * B * C > max) max = A * B * C; if (A * B * C < min) min = A * B * C; A = (n / i) / j + 1; B = j + 2; C = i + 2; if (A * B * C > max) max = A * B * C; if (A * B * C < min) min = A * B * C; } } } } cout << min - n << ' ' << max - n << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long mas[3]; int main() { long long min = 0x7fffffffffffffff; long long max = 0; int n; cin >> n; for (long long a = 1; a * a * a <= n; ++a) { if (n % a == 0) { for (long long b = a; b * b <= n / a; ++b) if ((n / a) % b == 0) { long long c = n / a / b; mas[0] = a; mas[1] = b; mas[2] = c; sort(mas, mas + 3); do { if ((mas[0] + 1) * (mas[1] + 2) * (mas[2] + 2) < min) { min = (mas[0] + 1) * (mas[1] + 2) * (mas[2] + 2); } if ((mas[0] + 1) * (mas[1] + 2) * (mas[2] + 2) > max) { max = (mas[0] + 1) * (mas[1] + 2) * (mas[2] + 2); } } while (next_permutation(mas, mas + 3)); } } } cout << min - n << " " << max - n; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; long long minans = 1e9 + 7 * 1e9 + 7, maxans = -1; void update(long long now) { minans = min(minans, now); maxans = max(maxans, now); } int main() { long long n; cin >> n; for (long long i = 1; i <= sqrt(n) + 1; i++) { if (n % i) continue; for (long long j = i; j <= sqrt(n / i) + 1; j++) { if ((n / i) % j) continue; long long k = n / i / j; update((i + 1) * (j + 2) * (k + 2)); update((i + 2) * (j + 1) * (k + 2)); update((i + 2) * (j + 2) * (k + 1)); } } cout << minans - n << ' ' << maxans - n << endl; return 0; }
#include <bits/stdc++.h> using namespace std; void find(long long x, long long* max, long long* min) { long long sqx, minx, maxx, j, y, aux; sqx = (long long)sqrt(x + 1); minx = 10000000000000; maxx = -1; for (j = 1; j <= sqx; j++) { if (!(x % j)) { y = x / j; aux = (y + 2) * (j + 2); maxx = maxx < aux ? aux : maxx; minx = minx > aux ? aux : minx; } } *max = maxx; *min = minx; } int main(void) { long long n, i, j, sqn, sqx, maxx, minx, min, max, aux, x, y; cin >> n; sqn = (long long)sqrt(n + 1); min = 100000000000; max = -1; for (i = 1; i <= sqn; i++) { if (!(n % i)) { x = n / i; find(x, &maxx, &minx); aux = (i + 1) * maxx; max = max < aux ? aux : max; aux = (i + 1) * minx; min = min > aux ? aux : min; find(i, &maxx, &minx); aux = (x + 1) * maxx; max = max < aux ? aux : max; aux = (x + 1) * minx; min = min > aux ? aux : min; } } cout << min - n << " " << max - n << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, n, i, j, k, max1 = 0, min1 = LLONG_MAX, product; cin >> n; for (a = 1; a * a * a <= n; ++a) { if (n % a == 0) { for (b = a; b * b <= n / a; ++b) { if ((n / a) % b == 0) { c = (n / a) / b; i = a + 2, j = b + 2, k = c + 1; if (i * j * k - a * b * c > max1) max1 = i * j * k - a * b * c; if (i * j * k - a * b * c < min1) min1 = i * j * k - a * b * c; i = b + 2, j = c + 2, k = a + 1; if (i * j * k - a * b * c > max1) max1 = i * j * k - a * b * c; if (i * j * k - a * b * c < min1) min1 = i * j * k - a * b * c; i = c + 2, j = a + 2, k = b + 1; if (i * j * k - a * b * c > max1) max1 = i * j * k - a * b * c; if (i * j * k - a * b * c < min1) min1 = i * j * k - a * b * c; } } } } cout << min1 << " " << max1; return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; int main() { int n; cin >> n; unsigned long long mx, mn; mx = mn = 0; for (unsigned long long i = 1; i * i * i <= n; i++) for (unsigned long long j = 1; j * j <= n / i; j++) { unsigned long long k1 = n; if (k1 % i) continue; k1 /= i; if (k1 % j) continue; k1 /= j; unsigned long long ar[3] = {i, j, k1}; sort(ar, ar + 3); do { unsigned long long res = (ar[0] + 1) * (ar[1] + 2) * (ar[2] + 2) - n; if (mx == 0 || mx < res) mx = res; if (mn == 0 || mn > res) mn = res; } while (next_permutation(ar, ar + 3)); } cout << mn << " " << mx; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; scanf("%I64d", &n); long long mn = 1LL << 40, mx = 1; for (long long i = 1; i * i * i <= n; ++i) if (n % i == 0) { long long nn = n / i; for (long long j = 1; j * j <= nn; ++j) if (nn % j == 0) { long long k = nn / j; long long val1 = (i + 1) * (j + 2) * (k + 2); long long val2 = (i + 2) * (j + 1) * (k + 2); long long val3 = (i + 2) * (j + 2) * (k + 1); mn = min(mn, min(val1, min(val2, val3))); mx = max(mx, max(val1, max(val2, val3))); } } printf("%I64d %I64d", mn - n, mx - n); }
#include <bits/stdc++.h> using namespace std; int main() { long long n, ans1, ans2 = LONG_LONG_MAX; cin >> n; ans1 = 3LL * 3LL * (n + 1); for (long long a = 1; a * a * a <= n; a++) { if (n % a == 0) { for (int b = a; b * b <= n / a; b++) { if ((n / a) % b == 0) { long long c = n / a / b; ans2 = min(ans2, (a + 1) * (b + 2) * (c + 2)); ans2 = min(ans2, (a + 2) * (b + 1) * (c + 2)); ans2 = min(ans2, (a + 2) * (b + 2) * (c + 1)); } } } } cout << ans2 - n << " " << ans1 - n << endl; return 0; }
#include <bits/stdc++.h> using namespace std; void solve(long long n) { long long A, B, C; long long A1, B2, C2; long long minres = numeric_limits<long long>::max(); long long maxres = numeric_limits<long long>::min(); for (A1 = 1; A1 <= n / A1; A1++) { if (n % A1 == 0) { long long a1[2] = {A1, n / A1}; for (int i = 0; i < 2; i++) { long long n1 = n / (a1[i]); A = a1[i] + 1; for (B2 = 1; B2 <= n1 / B2; B2++) { if (n1 % B2 == 0) { B = B2 + 2; C = (n1 / B2) + 2; long long dif = 2 * A * B + 2 * A * C - 4 * A + B * C - 2 * B - 2 * C + 4; minres = std::min(minres, dif); maxres = std::max(maxres, dif); } } } } } cout << minres << " " << maxres << endl; } inline void init() {} int main() { init(); int n; while (cin >> n) { solve(n); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long int INF = (1LL << 51); const long long int MRAD = (4 * 10100); long long int n, ansl, ansh; vector<long long int> d; void enans(int i, int j) { long long int x; x = (d[i] + 1LL) * (d[j] + 2LL) * ((n / (d[i] * d[j])) + 2LL); ansl = min(ansl, x - n); ansh = max(ansh, x - n); } int main() { cin >> n; ansl = INF; ansh = -INF; long long int x; for (long long int i = 1LL; i < 35000LL; i += 1LL) { if (i > n) break; if (n % i != 0) continue; for (long long int j = i; j < 35000LL; j += 1LL) { if (i * j > n) break; if ((n / i) % j != 0) continue; x = (i + 1LL) * (j + 2LL) * ((n / (i * j)) + 2LL); ansl = min(ansl, x - n); ansh = max(ansh, x - n); x = (i + 2LL) * (j + 1LL) * ((n / (i * j)) + 2LL); ansl = min(ansl, x - n); ansh = max(ansh, x - n); x = (i + 2LL) * (j + 2LL) * ((n / (i * j)) + 1LL); ansl = min(ansl, x - n); ansh = max(ansh, x - n); } } cout << ansl << ' ' << ansh << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; long long n; int main() { scanf("%I64d", &n); long long sol1, sol2, a, b, c, d; sol1 = sol2 = (n + 1) * 9; for (a = 1; a * a * a <= n; ++a) { if (n % a != 0) continue; for (b = a; a * b * b <= n; ++b) { if (n % (a * b) != 0) continue; c = n / (a * b); if (c < b) break; d = (a + 1) * (b + 2) * (c + 2); sol1 = min(sol1, d); sol2 = max(sol2, d); } } for (c = 1; c * c * c <= n; ++c) { if (n % c != 0) continue; for (b = c; c * b * b <= n; ++b) { if (n % (b * c) != 0) continue; a = n / (b * c); if (a < b) break; d = (a + 1) * (b + 2) * (c + 2); sol1 = min(sol1, d); sol2 = max(sol2, d); } } printf("%I64d %I64d\n", sol1 - n, sol2 - n); return 0; }
#include <bits/stdc++.h> using namespace std; const long long inf = (1000 * 1000 * 1000 * 1ll) * (1000 * 1000 * 1000 * 1ll); int main() { int size = 0; long long n, mn = inf, mx = -1, a[5000]; cin >> n; a[size++] = 1; a[size++] = n; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { a[size++] = i; a[size++] = n / i; } } sort(a, a + size); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) if (n % (a[i] * a[j]) == 0) { mx = max(mx, (a[i] + 1) * (a[j] + 2) * (n / a[i] / a[j] + 2)); mn = min(mn, (a[i] + 1) * (a[j] + 2) * (n / a[i] / a[j] + 2)); } } cout << mn - n << " " << mx - n; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ai, bi, ci, am, bm, cm; long long mi = (200000000000ll), ma = -1; for (int i = 1; i * i * i <= n; i++) if (n % i == 0) { for (int j = 1; j * j <= (n / i); j++) { if (n % (i * j) == 0) { long long a = i + 1, b = j + 2, c = n / (i * j) + 2; mi = min(mi, (a * b * c) - n); ma = max(ma, (a * b * c) - n); a = i + 2; b = j + 1; c = n / (i * j) + 2; mi = min(mi, (a * b * c) - n); ma = max(ma, (a * b * c) - n); a = i + 2; b = j + 2; c = n / (i * j) + 1; mi = min(mi, (a * b * c) - n); ma = max(ma, (a * b * c) - n); } } } cout << mi << " " << ma; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; long long n; int main() { scanf("%d", &n); long long mn = 1e18, mx = -1; for (long long a = 1; a * a * a <= n; a++) if ((n % a) == 0) for (long long b = a; b * b <= (n / a); b++) if ((n / a) % b == 0) { long long c = (n / a) / b; long long k1, k2, k3; k1 = (a + 1) * (b + 2) * (c + 2); k2 = (b + 1) * (a + 2) * (c + 2); k3 = (c + 1) * (b + 2) * (a + 2); mx = max(mx, max(k1, max(k2, k3))); mn = min(mn, min(k1, min(k2, k3))); } printf("%lld %lld\n", mn - n, mx - n); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j; long long Max = 0, Min = 9223372036854775807LL, p; vector<int> x; cin >> n; for (i = 1; i <= sqrt(n) + 1; i++) if (n % i == 0) x.push_back(i), x.push_back(n / i); x.push_back(n); m = x.size(); for (i = 0; i < m; i++) for (j = 0; j < m; j++) { long long b = (long long)(x[i]) * x[j]; if (n % b == 0) { int l = n / (x[i] * x[j]); p = (long long)(x[i] + 1) * (long long)(x[j] + 2); p *= (long long)(l + 2); p -= n; if (p > 0 && p > Max) Max = p; if (p > 0 && p < Min) Min = p; } } cout << Min << " " << Max << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int EPS = 1e-6; const long long INF = 1e15; const long long mod = (int)(1e+9 + 7); const int N = (int)(0); int r3(int n) { int i = 1; for (; i * i * i <= n; i++) ; return i - 1; } int main() { int n; cin >> n; long long M = 0, m = INF; int a[3]; for (a[0] = 1; (a[0]) * (a[0]) * (a[0]) <= n; a[0]++) { if (n % a[0] != 0) continue; for (a[1] = 1; (a[1]) * (a[1]) <= n / a[0]; a[1]++) { if ((n / a[0]) % a[1] != 0) continue; a[2] = (n / a[0]) / a[1]; for (int i = 0; i < 3; i++) { M = max(M, 1LL * (a[i] + 1) * (a[(i + 1) % 3] + 2) * (a[(i + 2) % 3] + 2)); m = min(m, 1LL * (a[i] + 1) * (a[(i + 1) % 3] + 2) * (a[(i + 2) % 3] + 2)); } } } cout << m - n << " " << M - n; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n; long long a, b, c, i, j, k; long long mn = 1000000000000009ll; long long mx = 0ll; for (i = 1; i * i * i <= n; i++) { for (j = i; j * j * i <= n; j++) { k = n / (i * j); if (i * j * k == n) { long long a = max(i, max(j, k)); long long b = min(i, min(j, k)); long long c = i + j + k - a - b; long long tot = (a + 1) * (b + 2) * (c + 2); mn = min(mn, tot - i * j * k); mx = max(mx, tot - i * j * k); tot = (b + 1) * (a + 2) * (c + 2); mn = min(mn, tot - i * j * k); mx = max(mx, tot - i * j * k); tot = (c + 1) * (a + 2) * (b + 2); mn = min(mn, tot - i * j * k); mx = max(mx, tot - i * j * k); } } } cout << mn << " " << mx << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, mins = -1ll, maxs = -1ll, k, s; vector<long long> v; cin >> n; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { v.push_back(i); v.push_back(n / i); } } for (int i = 0; i < v.size(); i++) { for (int j = 0; j < v.size(); j++) { if (n % (v[i] * v[j]) == 0) { k = n / (v[i] * v[j]); s = max(((v[i] + 1) * (v[j] + 2) * (k + 2) - v[i] * v[j] * k), max((v[i] + 2) * (v[j] + 1) * (k + 2) - v[i] * v[j] * k, (v[i] + 2) * (v[j] + 2) * (k + 1) - v[i] * v[j] * k)); if (s > maxs || maxs == -1) { maxs = s; } s = min(((v[i] + 1) * (v[j] + 2) * (k + 2) - v[i] * v[j] * k), min((v[i] + 2) * (v[j] + 1) * (k + 2) - v[i] * v[j] * k, (v[i] + 2) * (v[j] + 2) * (k + 1) - v[i] * v[j] * k)); if (s < mins || mins == -1) { mins = s; } } } } cout << mins << " " << maxs; return 0; }
#include <bits/stdc++.h> using namespace std; long long a, b, c, n, i, j, res1 = 1e12, res2 = -1e12; vector<long long> d; int main() { cin >> n; for (i = 1; i * i <= n; i++) if (n % i == 0) { d.push_back(i); if (n / i != i) d.push_back(n / i); } for (i = 0; i < d.size(); i++) for (j = 0; j < d.size(); j++) { a = d[i]; b = d[j]; if (n % (a * b) == 0) { c = n / (a * b) + 2; a++; b += 2; res1 = min(res1, a * b * c); res2 = max(res2, a * b * c); } } cout << res1 - n << " " << res2 - n << endl; }
#include <bits/stdc++.h> using namespace std; const signed long long Infinity = 1000000001; const long double Pi = 2.0L * asinl(1.0L); const long double Epsilon = 0.000000001; template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << "(" << p.first << "," << p.second << ")"; } template <class T> ostream& operator<<(ostream& os, const vector<T>& V) { for (typeof(V.begin()) i = V.begin(); i != V.end(); ++i) os << *i << endl; return os; } template <class T> ostream& operator<<(ostream& os, const set<T>& S) { for (typeof(S.begin()) i = S.begin(); i != S.end(); ++i) os << *i << endl; return os; } template <class T, class U> ostream& operator<<(ostream& os, const map<T, U>& M) { for (typeof(M.begin()) i = M.begin(); i != M.end(); ++i) os << *i << endl; return os; } vector<pair<int, int> > getFactors(int n) { map<int, int> M; for (int i = 2; i * i <= n; i++) { while (n % i == 0) { M[i]++; n /= i; } } if (n != 1) M[n]++; vector<pair<int, int> > R; for (typeof(M.begin()) i = M.begin(); i != M.end(); ++i) R.push_back(*i); return R; } inline int FMP(int a, int x) { int r = 1; while (x != 0) { if (x & 1) r *= a; a *= a; x >>= 1; } return r; } vector<int> getDivisors(const vector<pair<int, int> >& factors) { vector<int> r; int q = 1; for (typeof(factors.begin()) i = factors.begin(); i != factors.end(); ++i) q *= i->second + 1; r.resize(q); int t = 0; for (int(i) = (0); (i) < (q); (i)++) { int l = i; int g = 1; for (typeof(factors.begin()) j = factors.begin(); j != factors.end(); ++j) { int a = j->first; int x = l % (j->second + 1); g *= FMP(a, x); l /= j->second + 1; } r[t++] = g; } return r; } int main() { int n; cin >> n; vector<int> D = getDivisors(getFactors(n)); sort(D.begin(), D.end()); signed long long rmin = 1000000000000000000LL, rmax = -1; for (int(i) = (0); (i) < (D.size()); (i)++) for (int(j) = (0); (j) < (D.size()); (j)++) { signed long long a = D[i]; signed long long b = D[j]; signed long long c = (n / a) / b; if (a * b * c == n) { signed long long t = (a + 1) * (b + 2) * (c + 2) - a * b * c; rmin = min(rmin, t); rmax = max(rmax, t); } } cout << rmin << " " << rmax; return 0; }
#include <bits/stdc++.h> using namespace std; long long workmin(long long a, long long b, long long c, long long m) { long long num1, num2, num3, ans = 9999999999; num1 = a + 1, num2 = b + 2, num3 = c + 2; ans = min(ans, num1 * num2 * num3 - m); num1 = a + 1, num2 = c + 2, num3 = b + 2; ans = min(ans, num1 * num2 * num3 - m); num1 = b + 1, num2 = a + 2, num3 = c + 2; ans = min(ans, num1 * num2 * num3 - m); num1 = b + 1, num2 = c + 2, num3 = a + 2; ans = min(ans, num1 * num2 * num3 - m); num1 = c + 1, num2 = b + 2, num3 = a + 2; ans = min(ans, num1 * num2 * num3 - m); num1 = c + 1, num2 = a + 2, num3 = b + 2; ans = min(ans, num1 * num2 * num3 - m); return ans; } long long workmax(long long a, long long b, long long c, long long m) { long long num1, num2, num3, ans = 0; num1 = a + 1, num2 = b + 2, num3 = c + 2; ans = max(ans, num1 * num2 * num3 - m); num1 = a + 1, num2 = c + 2, num3 = b + 2; ans = max(ans, num1 * num2 * num3 - m); num1 = b + 1, num2 = a + 2, num3 = c + 2; ans = max(ans, num1 * num2 * num3 - m); num1 = b + 1, num2 = c + 2, num3 = a + 2; ans = max(ans, num1 * num2 * num3 - m); num1 = c + 1, num2 = b + 2, num3 = a + 2; ans = max(ans, num1 * num2 * num3 - m); num1 = c + 1, num2 = a + 2, num3 = b + 2; ans = max(ans, num1 * num2 * num3 - m); return ans; } int main() { long long m, n, i, j, k, a, b, c, ansmin = 9999999999999999, ansmax = 0; cin >> m; for (i = 1; i <= sqrt(m); i++) { a = i; if (m % a == 0) { long long num = m / a; for (j = 1; j <= sqrt(num); j++) { if (num % j == 0) { b = j, c = num / j; ansmin = min(workmin(a, c, b, m), ansmin); ansmax = max(ansmax, workmax(a, b, c, m)); } } } } cout << ansmin << ' ' << ansmax << endl; }