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. 【JMeter】常用线程组设置策略

    常用线程组设置策略 目录 常用线程组设置策略 一.前言 二.单场景基准测试 1.介绍 2.线程组设计 3.测试结果 三.单场景并发测试 1.介绍 2.线程组设计 3.测试结果 四.单场景容量/爬坡测试 ...

  2. numpy和pandas的基本用法

    安装numpy模块 pip install numpy 可以通过导入numpy模块来使用它 import numpy as np 1.创建数组: a = np.array([1, 2, 3, 4, 5 ...

  3. Code Llama:Llama 2 学会写代码了!

    引言 Code Llama 是为代码类任务而生的一组最先进的.开放的 Llama 2 模型,我们很高兴能将其集成入 Hugging Face 生态系统!Code Llama 使用与 Llama 2 相 ...

  4. ATtiny88初体验(七):TWI

    ATtiny88初体验(七):TWI TWI模块介绍 ATtiny88的TWI模块兼容Phillips I2C以及SMBus,支持主从模式,支持7bit地址,最大允许128个不同的从机地址.在多主机模 ...

  5. 本计划在 .NET 8 中推出的 WASI 推迟到 .NET 9

    本计划在 .NET 8 中推出的 WASI  已推迟到 .NET 9,请参阅 Github 上的 WASI 跟踪问题. 在.NET 8 Preview 4 开始支持生成与 WASI 兼容的 .wasm ...

  6. Spring框架中 依赖注入和控制反转,最简单、最通俗的解释! 再加上一个AOP

    首先依赖注入 == 控制反转,只不过控制反转这个词汇,让人产生了错误的理解,才使用新的词汇:依赖注入来替换到这个词汇. "依赖注入"是指一个对象应用另外一个对象来提供一个特殊的能力 ...

  7. poj2279

    Mr. Young's Picture Permutations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5841   ...

  8. jq工具及其常用用法

    近来在工作中处理JSON处理较多,深入研究了一下jq,之前对jq的使用一直停留在JSON数据格式化的层面,实际它的能力远不止于此. 在处理JSON数据时,我们经常需要在命令行中进行过滤.查询和编辑的操 ...

  9. 如何通过代码混淆绕过苹果机审,解决APP被拒问题

    目录 iOS代码混淆 功能分析 实现流程 类名修改 方法名修改 生成垃圾代码 替换png等静态资源MD5 info.plist文件添加垃圾字段 功能分析 实现流程 类名修改 方法名修改 生成垃圾代码 ...

  10. Pushpin:开源即时通信神器,让你的API秒变实时API,轻松实现WebSocket,HTTP流和HTTP长轮询等服务

    作为一个开发者,你可能已经利用过REST API来构建和集成各种应用.REST API是基于HTTP协议的交互模式,它使得客户端和服务器可以通过请求和响应来进行数据交换,简单.灵活.通用. 然而,当你 ...