【CF#192 A】Funky Numbers (二分,查找,二元组)

题干:

As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.

A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number n, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!

Input

The first input line contains an integer n (1 ≤ n ≤ 109).

Output

Print "YES" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).

Examples

Input

256

Output

YES

Input

512

Output

NO

Note

In the first sample number .

In the second sample number 512 can not be represented as a sum of two triangular numbers.

题目大意:

给你一个数字N,问你是否存在两个数字A,B使得N=A(A+1)2+B(B+1)2N=A(A+1)2+B(B+1)2 

解题报告:

    优秀的二分,复杂度sqrtnlogn

#include<bits/stdc++.h>using namespace std;int main()
{int n;cin>>n;int tmp,key;int l ,r,mid;n*=2;for(int i = 1; i<=sqrt(n); i++) {tmp = i * (i+1);key = n-tmp;l = i;r = sqrt(n);while(l<=r) {mid = (l+r)/2;if(mid * (mid+1) < key) l=mid+1;else if(mid*(mid+1)>key) r = mid-1;else {printf("YES\n");return 0 ;}}}printf("NO\n");return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441666.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

matlab考试试题,matlab-考试试题-

matlab-考试试题- MATLAB 考试试题 (1) 产生一个1x10的随机矩阵&#xff0c;大小位于( -5 5)&#xff0c;并且按照从大到小的顺序排列好&#xff01;(注&#xff1a;要程序和运行结果的截屏)答案&#xff1a;a10*rand(1,10)-5;bsort(a, descend )1.请产生一个100*5 的矩阵&…

【HDU - 1022】Train Problem I (栈模拟,水题,思维)

题干&#xff1a; As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes a proble…

任意阶魔方阵matlab程序,【精品】任意阶魔方阵算法(c语言)

n阶幻方是由前n^2(n的2次方)个自然数组成的一个n阶方阵&#xff0c;其各行、各列及两条对角线所含的n个数的和相等。洛书就是最基本的33阶魔方阵&#xff0c;做出某种最恰当的决定&#xff0c;横竖都有3个格。 0的倒数 a&#xff0d;1可以对于 n 阶单位矩阵 e 以及同阶的方阵 a…

悟空php微信复制的东西在哪找,微信收藏的文件在哪?从哪里能看到?

现在的微信有很多的小功能&#xff0c;非常的方便实用&#xff0c;但是很多功能大家都不知道&#xff0c;今天&#xff0c;开淘网小编就来教教大家怎么使用微信的“我的收藏”功能。这个功能非常实用&#xff0c;而且收藏的源文件删除的话&#xff0c;我们从收藏里还是一样能用…

【OpenJ_Bailian - 2299 】Ultra-QuickSort (归并排序 或 离散化 + 树状数组)

题干&#xff1a; In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascending order. For the input sequ…

升级oracle spu,关于Oracle数据库PSU/SPU/BundlePatch的补丁号变化

思庄中心OCP脱产班1月15日开班&#xff0c;周末班于1月12日开班&#xff01;熟悉 OracleDatabase PSU、Bundle Patch 的DBA一定知道&#xff0c;一般来讲&#xff0c;这些 patch的命名规则一般是按照推出的先后顺序&#xff0c;比如在 2015年7月 推出的对 11.2.0.4 的第7个 DB …

【CodeForces - 569C】Primes or Palindromes? (思维,分析范围,暴力枚举判断)

题干&#xff1a; Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable propert…

linux data文件如何打开,DATA 文件扩展名: 它是什么以及如何打开它?

DATA 问题的来源常见的 DATA 打开问题Microsoft Excel 消失如果您尝试加载 DATA 文件&#xff0c;则会收到 “无法打开 DATA 文件” 等消息。 通常情况下&#xff0c;这意味着 Microsoft Excel 没有安装在 %%os%% 上。 通过双击打开 DATA 的典型路径将不起作用&#xff0c;因为…

【CodeForces - 574D】Bear and Blocks (dp,思维)

题干&#xff1a; Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification see picture for the first sample. Limak will repeat th…

【CodeForces - 574B】Bear and Three Musketeers (枚举边,思维,优秀暴力)

题干&#xff1a; Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to …

【CodeForces - 574C】Bear and Poker(思维,剪枝,数学)

题干&#xff1a; Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Ea…

stm32linux区别,STM32MPU和OpenSTLinux你了解多少?

早在2019年年初的时候&#xff0c;ST就发布了首款STM32MPU&#xff1a;STM32MP1。 STM32MP1通用微处理器产品系列&#xff0c;系基于混合的 双Arm Cortex-A7核 和 Cortex-M4核架构产品。 一、支持STM32MPU 生态系统熟悉 Cortex-M4 MCU 环境的开发人员能轻松实现他们的目标&…

linux安全模式改文件,嵌入式Linux的安全模式设计 - 嵌入式操作系统 - 电子发烧友网...

本系统的架构如下图&#xff1a;产品所使用的flash总大小为16M。系统包括三大部分&#xff0c;即Bootloader&#xff0c;config, kernel rootfs&#xff1a;另外&#xff0c;/dev/mtdblock/0&#xff0c;在系统中对应整个flash block&#xff0c;即整个16M空间。系统启动时&am…

基于arm下的Linux控制,基于ARMuCLinux的网络控制系统设计与实现

引言 随着网络和通信技术的发展&#xff0c;嵌入式系统现已进入高速发展阶段。并在社会各个领域得到了广泛的应用。本文介绍了一种采用ARMuCLinux作为开发平台。实现基于TCP&#xff0f;IP的远程系统监控&#xff0e;从而取代传统单片机来实现数据采集、预处理和通信功能&am…

nodejs 监控linux,linuxServerMonitoring

linux服务器监控平台技术&#xff1a;nodejs vue java mongodb springboot linux shelllinux服务器监控项目&#xff0c;前后端分离vuespringbootmongodb&#xff1a;1、启动前台&#xff1a;使用命令&#xff1a;A 先安装nodejs并配置好环境变量B 先控制台cmd命令切换到项目目…

c语言中short作用,C语言short

C语言short教程C语言short定义详解语法short int varname value;short varname1 value2; //简写形式参数参数描述short int定义 short 类型变量使用的类型。varname变量名。value可选&#xff0c;变量的初始值&#xff0c;该值不可以超过 short 类型的最大值。说明使用 short…

c语言学生对老师的评教系统,学生对老师的评价

学生对老师的评价1、老师授课的方式十分适合我们&#xff0c;他根据本课程知识结构的特点&#xff0c;重点突出&#xff0c;层次分明。理论和实际相结合&#xff0c;透过例题使知识更条理化。但授课速度有点快&#xff0c;来不及记录。2、老师在生活工作中给人的感觉是生活朴素…

【HDU - 1254 】推箱子 (双bfs)

题干&#xff1a; 推箱子是一个很经典的游戏.今天我们来玩一个简单版本.在一个M*N的房间里有一个箱子和一个搬运工,搬运工的工作就是把箱子推到指定的位置,注意,搬运工只能推箱子而不能拉箱子,因此如果箱子被推到一个角上(如图2)那么箱子就不能再被移动了,如果箱子被推到一面墙…

知识点 组合数学 卡特兰数

关于卡特兰数 卡特兰数是一种经典的组合数&#xff0c;经常出现在各种计算中&#xff0c;其前几项为 : 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, 477638700, 1767263190, 6564120420, 24466267020, 914…

Android万能遥控菜单选择添加,Android万能遥控器小应用

在很久很久以前&#xff0c;手机是有红外功能的&#xff0c;后来随着蓝牙技术的成熟&#xff0c;红外逐渐被蓝牙取代&#xff0c;不再是标配了。红外本身还是有些优点&#xff0c;比如操作简便&#xff0c;成本低。要想在手机上添加红外功能&#xff0c;就要外接一个转换模块。…