abc246_d 2-variable Function


考虑到i不大于1e6,而使得f(i,j)大于n的最小的j是随i的增加单调减的,因此枚举即可。

//
// Created by vv123 on 2022/4/2.
//
#include <bits/stdc++.h>
#define f(i,j) i*i*i+i*i*j+i*j*j+j*j*j
using namespace std;
typedef long long LL;
int main() {
    LL n, ans = 1e18, j = 1e6;
    cin >> n;
    for (long long i = 1; i <= 1e6; i++) {
        while (f(i, j) >= n && j >= 0) {
            ans = min(ans, f(i, j));
            j--;
        }
    }
    cout << ans << endl;
    return 0;
}

建议不要使用define,f的参数需确保为long long型。

posted @ 2022-04-03 11:17  _vv123  阅读(62)  评论(0编辑  收藏  举报