跳到正文

个人记录

ABC 397

Dtw_约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年5月29日
篇幅
约 2 分钟

版本

  1. v1当前

前言

被 B 和 D 卡了挺久的,实现的太粗糙。

D

给你 nn,求 (x,y)(x, y) 满足 x3−y3=nx^3 - y^3 = n。

Solution

一开始我的思路是枚举 x/yx/y 然后二分另一个数,但是这样的话 xx 可能到 4×1084\times10^8 级别,所以不对。

考虑枚举 x−yx-y,然后二分出 xx 就知道 x,yx,y 了,然后判断。

还可以直接立方差,然后枚举,可以不带 log⁡\log。

Code

C++
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ll __int128

#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

const int N = 1e6 + 10, inf = 0x3f3f3f3f;

signed main()
{
    fst
    int n; cin >> n;
    for (int i = 0; i <= N; i++)
    {
        ll x = 1ll * (i + 1) * (i + 1) * (i + 1);
        x -= 1;
        if (x > n) break;
        int l = 1, r = 2e9, res = 1;
        while (l <= r)
        {
            int mid = (l + r) / 2;
            ll o = 1, k = 1;
            for (int j = 1; j <= 3; j++) o = o * (i + mid), k = k * mid;
            if (o - k >= n) r = (res = mid) - 1;
            else l = mid + 1;
        }
        ll o = 1, k = 1;
        for (int j = 1; j <= 3; j++) o = o * (i + res), k = k * res;
        if (o - k == n) { cout << res + i << " " << res; return 0; }
    }
    cout << -1;
    return 0;
}

E

Solution。

F

Solution。

原文