[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节点的丢弃,取出,取出标签名称.属性.属 ...
随机推荐
- [python] 第一个爬虫, 爬妹子写真集图片
效果图 版本以及需要用到的第三方库 python 2.7 bs4 (安装命令: pip install bs4) - 代码 #!/usr/bin/env python #coding:UTF-8 #脚 ...
- 关闭Google"阻止了登录尝试"方法, 其他设备也能登录Gmail等谷歌服务
首先登录谷歌账户, 访问 https://www.google.com/settings/security/lesssecureapps 把"不够安全的应用的访问权限" 启用打勾 ...
- 7.4 通过API枚举进程权限
GetTokenInformation 用于检索进程或线程的令牌(Token)信息.Token是一个数据结构,其包含有关进程或线程的安全上下文,代表当前用户或服务的安全标识符和权限信息.GetToke ...
- Redis和Memcache区别,优缺点对比(转)
转自 https://www.cnblogs.com/JavaBlackHole/p/7726195.html 1. Redis和Memcache都是将数据存放在内存中,都是内存数据库.不过memca ...
- Http协议之libcurl实现
一.libcurl简介 libcurl是一个跨平台的网络协议库,支持http, https, ftp, gopher, telnet, dict, file, 和ldap 协议.libcurl同样支持 ...
- 个人理解strcpy
char * strcpy(char *dst,const char *src) { if((dst==NULL)||(src==NULL)) return NULL; char *ret = dst ...
- 点云配准算法-旋转矩阵估计-Kabsch-Umeyama algorithm
Kabsch-Umeyama algorithm 参考文献: https://www.wikiwand.com/en/Kabsch_algorithm 面向点云配准,最小化两点集均方根误差(RMSD, ...
- junit4单元测试报错Invalid project specified
junit4单元测试报错Invalid project specified. 前天在进行单元测试的时候出现了Invalid project specified的报错查了一下发现是项目名字的问题.项目名 ...
- 删除小程序scroll-view的滚动条
小程序scroll-view滚动条很丑,想隐藏? 在有scroll-view滚动条页面的wxss里添加: ::-webkit-scrollbar { display: none; width: 0; ...
- 多维评测指标解读第17届MSU世界编码器大赛全高清10bit赛道结果
超高清视频纤毫毕现的关键一环. 01 主要指标多项第一,带宽节省48% 近日,第17届MSU世界编码器大赛全高清10bit赛道成绩揭晓,阿里自研的H.266/VVC编码器Ali266在该赛道最高效的1 ...