Problem Statement

Given an integer $N$, find the smallest integer $X$ that satisfies all of the conditions below.

  • $X$ is greater than or equal to $N$.
  • There is a pair of non-negative integers $(a, b)$ such that $X=a^3+a^2b+ab^2+b^3$.

Constraints

  • $N$ is an integer.
  • $0 \le N \le 10^{18}$

Input

Input is given from Standard Input in the following format:

$N$

Output

Print the answer as an integer.


Sample Input 1

9

Sample Output 1

15

For any integer $X$ such that $9 \le X \le 14$, there is no $(a, b)$ that satisfies the condition in the statement.

For $X=15$, $(a,b)=(2,1)$ satisfies the condition.


Sample Input 2

0

Sample Output 2

0

$N$ itself may satisfy the condition.


Sample Input 3

999999999989449206

Sample Output 3

1000000000000000000

Input and output may not fit into a $32$-bit integer type.

\(a^3+a^2b+ab^2+b^3=(a+b)^3-2ab(a+b)\)

我们不妨枚举 \(a+b\) 为多少,\((a+b)^3\) 是 \(\theta(n^{\frac{1}{3}})\) 级别的。可以直接枚举。

我们现在知道了 (a+b),那么我们需要找到是否有 一组 \((a,b)\) 满足上面那个等式。因为和已经确定了,那么剩下的是一个二次函数,具有单调性。我们可以二分 \(a\),求出 \(b\),找到最接近的那个解就行了。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n,ans=2e18,l,r,md;
int main()
{
scanf("%lld",&n);
for(LL i=0;i<=2000005;i++)
{
if(i*i*i<n)
continue;
l=0,r=i/2;
while(l<=r)
{
md=l+r>>1;
if(i*i*i-2*md*(i-md)*i>=n)
l=md+1;
else
r=md-1;
}
if(i*i*i-2*r*(i-r)*i>=n)
ans=min(ans,i*i*i-2*r*(i-r)*i);
}
printf("%lld",ans);
}

[ABC246D] 2-variable Function的更多相关文章

  1. OPEN CASCADE Multiple Variable Function

    OPEN CASCADE Multiple Variable Function eryar@163.com Abstract. Multiple variable function with grad ...

  2. Lua function 函数

    Lua支持面向对象,操作符为冒号‘:’.o:foo(x) <==> o.foo(o, x). Lua程序可以调用C语言或者Lua实现的函数.Lua基础库中的所有函数都是用C实现的.但这些细 ...

  3. Named function expressions demystified

    Introduction Surprisingly, a topic of named function expressions doesn't seem to be covered well eno ...

  4. Model Representation and Cost Function

    Model Representation To establish notation for future use, we’ll use x(i) to denote the “input” vari ...

  5. USE " cc.exports.* = value " INSTEAD OF SET GLOBAL VARIABLE"

    Cocos2d-x 3.5的lua项目生成后,变成了MVC模式,并且,加入了一个全局变量的检测功能.也就是说,你不小心用了全局变量,他会提示你出错! 比如 local temp = 1 temp = ...

  6. Lecture0 -- Introduction&&Linear Regression with One Variable

    Introduction What is machine learning? Tom Mitchell provides a more modern definition: "A compu ...

  7. Apply Newton Method to Find Extrema in OPEN CASCADE

    Apply Newton Method to Find Extrema in OPEN CASCADE eryar@163.com Abstract. In calculus, Newton’s me ...

  8. 《JavaScript 代码优化指南》

      ~~教你向老鸟一样敲代码~~. 1. 将脚本放在页面的底部 ... <script src="./jquery.min.js"></script> &l ...

  9. CodeAtlas For Sublime Text

    CodeAtlas is a plugin of SublimeText, which allows one to explore the call graph conveniently. The p ...

  10. R自动数据收集第二章HTML笔记1(主要关于handler处理器函数和帮助文档所有示例)

    本文知识点:     1潜在畸形页面使用htmlTreeParse函数 2startElement的用法 3闭包 4handler函数的命令和函数体主要写法 5节点的丢弃,取出,取出标签名称.属性.属 ...

随机推荐

  1. C# MySqlHelp类 "DbModel.MySql"数据库操作类

    以前做易语言/PHP的. 最近刚入门C#, 就简单的封装了一个类库, 边学边玩才容易学到东西嘛, 比起sqlserver, 我还是觉得mysql更加有亲切感; 于是模仿ThinkPHP编写了一个&qu ...

  2. js监控微信浏览器的自带的返回事件(延迟解决微信返回立即执行popstate事件)

    /** * 浏览器回退事件监听 */ var listenerBackHandler = { param: { isRun: false, //防止微信返回立即执行popstate事件 }, list ...

  3. Field 'xxxxxx' doesn't have a default value 错误的解决办法

    在写web项目的时候,出现 Field 'xxxxx' doesn't have a default value 这个错误,直接找到你的数据库,然后打开设计表,看下面自增递增是否勾选上了,如果没有勾上 ...

  4. 小米云原生文件存储平台化实践:支撑 AI 训练、大模型、容器平台多项业务

    小米作为全球知名的科技巨头公司,已经在数百款产品中广泛应用了 AI 技术,这些产品包括手机.电视.智能音箱.儿童手表和翻译机等.这些 AI 应用主要都是通过小米的深度学习训练平台完成的. 在训练平台的 ...

  5. Eclipse OSGI配置文件说明

  6. 8.2 BeingDebugged

    BeingDebugged 是Windows系统PEB结构体中的一个成员,它是一个标志位,用于标识当前进程是否正在被调试.BeingDebugged的值为0表示当前进程未被调试,值为1表示当前进程正在 ...

  7. 一次考试的简单T3

    我的第一个想法其实是毫无头绪 根本就想不到dp,直接就写了爆搜后来讲了才知道... 这种dp的状态好像是一类dp的模型,他们的状态都有这样的一维:以第i个数结尾.这样的dp有什么样的标志呢?以第i个数 ...

  8. 可视化-vscode安装pandas

    pandas 是基于NumPy 的一种工具,该工具是为解决数据分析任务而创建的.Pandas 纳入了大量库和一些标准的数据模型,提供了高效地操作大型数据集所需的工具.pandas提供了大量能使我们快速 ...

  9. 告别空指针让代码变优雅,Optional使用图文例子源码解读

    一.前言 我们在开发中最常见的异常就是NullPointerException,防不胜防啊,相信大家肯定被坑过! 这种基本出现在获取数据库信息中.三方接口,获取的对象为空,再去get出现! 解决方案当 ...

  10. VLAN虚拟网络

    VLAN 名称:vlan 虚拟局域网(virtual LAN) 用途 由于交换机所有的端口都在同一广播域,只要发送广播会产生大量的垃圾信息,同时会有病毒的安全隐患(病毒). 为了解决上述问题 1.物理 ...