[ABC246D] 2-variable Function
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的更多相关文章
- OPEN CASCADE Multiple Variable Function
OPEN CASCADE Multiple Variable Function eryar@163.com Abstract. Multiple variable function with grad ...
- Lua function 函数
Lua支持面向对象,操作符为冒号‘:’.o:foo(x) <==> o.foo(o, x). Lua程序可以调用C语言或者Lua实现的函数.Lua基础库中的所有函数都是用C实现的.但这些细 ...
- Named function expressions demystified
Introduction Surprisingly, a topic of named function expressions doesn't seem to be covered well eno ...
- Model Representation and Cost Function
Model Representation To establish notation for future use, we’ll use x(i) to denote the “input” vari ...
- USE " cc.exports.* = value " INSTEAD OF SET GLOBAL VARIABLE"
Cocos2d-x 3.5的lua项目生成后,变成了MVC模式,并且,加入了一个全局变量的检测功能.也就是说,你不小心用了全局变量,他会提示你出错! 比如 local temp = 1 temp = ...
- Lecture0 -- Introduction&&Linear Regression with One Variable
Introduction What is machine learning? Tom Mitchell provides a more modern definition: "A compu ...
- 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 ...
- 《JavaScript 代码优化指南》
~~教你向老鸟一样敲代码~~. 1. 将脚本放在页面的底部 ... <script src="./jquery.min.js"></script> &l ...
- CodeAtlas For Sublime Text
CodeAtlas is a plugin of SublimeText, which allows one to explore the call graph conveniently. The p ...
- R自动数据收集第二章HTML笔记1(主要关于handler处理器函数和帮助文档所有示例)
本文知识点: 1潜在畸形页面使用htmlTreeParse函数 2startElement的用法 3闭包 4handler函数的命令和函数体主要写法 5节点的丢弃,取出,取出标签名称.属性.属 ...
随机推荐
- CentOS7.9中的Glibc2.17源码编译升级到Glibc2.31
一.准备工作 1.配置yum阿里镜像源 查看yum当前配置的仓库,如果yum配置的不是阿里云源,请配置阿里云源. yum repolist all 验证是否能ping通阿里云 # 如果不能ping通可 ...
- 在移动硬盘上安装Win11系统(不使用工具)
一.准备镜像文件 1.前往官网下载Win11镜像文件. Win11官网:Download Windows 11 (microsoft.com) 2.装载Win11镜像 找到Win11镜像.右键点击装载 ...
- 每日一库:pprof简介
pprof简介 pprof是Go语言的一个性能分析库,它可以帮助开发者找出程序中的性能瓶颈.pprof提供了CPU分析.内存分析.阻塞分析等多种性能分析功能. 以下是pprof的主要特性: CPU分析 ...
- 「atcoder - ABC215G」Colorful Candies 2
link. 称题目中的 \(c_i\) 为 \(a_i\),令 \(c_i\) 为第 \(i\) 种颜色的出现次数,令 \(C\) 为颜色总数.固定 \(k\),令 \(t_i=1\),如果颜色 \( ...
- python实现简单的爬虫功能
前言Python是一种广泛应用于爬虫的高级编程语言,它提供了许多强大的库和框架,可以轻松地创建自己的爬虫程序.在本文中,我们将介绍如何使用Python实现简单的爬虫功能,并提供相关的代码实例. 如何实 ...
- Python常用模块-20个常用模块总结
目录 time模块 datetime模块 random 模块 os 模块 sys 模块 json 和 pickle 模块 hashlib和hmac 模块 logging 模块 numpy 模块 pan ...
- Flask框架——flask介绍
文章目录 1 什么是flask? 2 为什么要有flask? 3 学前准备:虚拟环境 3.1 虚拟环境是什么? 3.2 如何使用虚拟环境? 3.2.1 搭建虚拟环境 3.2.1 在虚拟环境中安装我们的 ...
- 若依vue分离版(ruoyi-vue)跳过token验证,设置白名单
找到SecurityConfig类的configure方法 如图所示 在设置白名单后还需要把接口上的权限标识符去掉.然后需要重启一下项目,热加载不行,会报错.
- 普冉PY32系列(九) GPIO模拟和硬件SPI方式驱动无线收发芯片XL2400
目录 普冉PY32系列(一) PY32F0系列32位Cortex M0+ MCU简介 普冉PY32系列(二) Ubuntu GCC Toolchain和VSCode开发环境 普冉PY32系列(三) P ...
- Java-全网最详细反射
Java-反射 前言 Java的反射(reflection)机制是指在程序的运行状态中,可以构造任意一个类的对象,可以了解任意一个对象所属的类,可以了解任意一个类的成员变量和方法,可以调用任意一个对象 ...