結果

問題 No.2078 魔抜けなパープル
ユーザー tktk_snsntktk_snsn
提出日時 2022-09-26 20:04:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,636 bytes
コンパイル時間 741 ms
コンパイル使用メモリ 92,256 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 03:02:01
合計ジャッジ時間 1,477 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 17 ms
4,380 KB
testcase_02 AC 12 ms
4,380 KB
testcase_03 AC 15 ms
4,376 KB
testcase_04 AC 11 ms
4,380 KB
testcase_05 AC 11 ms
4,376 KB
testcase_06 AC 24 ms
4,380 KB
testcase_07 AC 12 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }
    
}
0