結果
問題 | No.2078 魔抜けなパープル |
ユーザー |
![]() |
提出日時 | 2022-09-26 20:04:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 1,636 bytes |
コンパイル時間 | 893 ms |
コンパイル使用メモリ | 94,904 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-22 15:41:11 |
合計ジャッジ時間 | 1,552 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 7 |
ソースコード
#include <iostream> #include <vector> #include <map> #include <algorithm> #include <set> #include <stack> #include <queue> #include <cmath> #include <iomanip> #include <numeric> #include <string> #include <bitset> #include <assert.h> #include <functional> // #define _GLIBCXX_DEBUG // #define _LIBCPP_DEBUG 0 #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define revrep(i, n) for(int i = (int)(n - 1); i >= 0; --i) #define range(i, s, t) for (int i = (int)(s); i < (int)(t); ++i) #define revrange(i, s, t) for(int i = (int)(t - 1); i >= (int)(s); --i) #define srange(i, s, t, step) for(int i = (int)(s); i < (int)(t); i+=int(step)) #define popcnt(x) __builtin_popcountll(x) #define wakarahen std::ios::sync_with_stdio(false);std::cin.tie(nullptr) using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<long long, long long>; template<class T> inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; } inline bool inside(int x, int y, int h, int w) { return (x >= 0 && x < h && y >= 0 && y < w); } int dx[] = {0, -1, 0, 1}; int dy[] = {-1, 0, 1, 0}; const ll inf = 1e18; ll solve() { ll x, a; cin >> x >> a; ll ans = inf; range(i, 1, a + 1) { ll div = a / i; ll mod = a % i; ll tmp = mod * (div + 1) * (div + 1); tmp += (i - mod) * div * div; tmp += i * x; chmin(ans, tmp); } return ans; } int main() { int t; cin >> t; while (t--) { cout << solve() << endl; } }