Funky Numbers(二分)

保姆级教程:在MounRiver Studio上为CH32V307配置FreeRTOS与LwIP网络栈 本文提供了一份详细的教程,指导如何在MounRiver Studio上为CH32V307配置FreeRTOS与LwIP网络栈。从开发环境搭建到网络功能验证,涵盖了FreeRTOS内核定制、LwIP协议栈配置、硬件抽象层实现等关键步骤,帮助开发者快速掌握RISC-V架构下的嵌入式网络开发。 阅读详情

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.

两个循环搜索会超时,所以第二个使用二分搜索

#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,i,A,B,mid,r,l;
    cin>>n;
    int flag=0;
    for(i=1;i<sqrt(2*n);i++){
        A=i*(i+1)/2;
        l=i;r=sqrt(2*n);mid=(l+r)/2;
        while(l<=r){
            B=mid*(mid+1)/2;
            if(A+B<n){
                l=mid+1;
                mid=(l+r)/2;
            }
            else if(A+B>n){
                r=mid-1;
                mid=(l+r)/2;
            }
            else{
                flag=1;
                break;
            }
            
        }
        if(flag==1)
            break;
    }
    if(flag==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    
    
    return 0;
}

【GameFramework框架】三、快速启动 这篇文章就带领大家如何快速启动GameFramework框架。 阅读详情

相关推荐

ZYNQ开发(2)在Linux系统层上PL-PS通过AXI-DMA传输数据详细步骤及注意事项

参考的网络资料 https://github.com/bperez77/xilinx_axidma/tree/master https://gitlab.gnome.org/HosseinBeheshti/UlteraZed7EV/-/tree/master/petalinux/xilinx_axidma https://www.icode9.com/content-3-925319.html https://blog.youkuaiyun.com/weixin_38218267/article/details/1

aizaiyueye的专栏 3448

Funky Numbers

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

beloved_yu的博客 430

K8s认证文件丢失的应急处理与恢复策略

本文详细介绍了Kubernetes(K8s)认证文件丢失时的应急处理与恢复策略。从快速诊断问题范围到不同场景的临时解决方案,再到深度恢复方案(无损重建、部分重置、完全重建),提供了全面的操作指南。同时强调了生产环境中的防丢失设计、高可用集群的特殊处理以及日常运维建议,帮助运维人员有效应对认证文件丢失的紧急情况。

weixin_33743248的博客 327

<cf> Funky Numbers

A. Funky Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output As you very well know, this ye...

weixin_34240657的博客 333

[漏洞挖掘与防护] 03.漏洞利用之WinRAR安全缺陷复现(CVE-2018-20250)及软件自启动分析

上一篇文章将详细介绍MS08-067远程代码执行漏洞(CVE-2008-4250)及防御过程,它是Windows Server服务RPC请求缓冲区溢出漏洞,利用445端口,并通过Metasploit工具获取shell及进行深入的操作。这篇文章将详细讲解WinRAR漏洞(CVE-2018-20250),并复现了该漏洞和讲解了恶意软件自启动劫持原理。基础性文章,希望对入门的同学有帮助。

杨秀璋的专栏 1088

iStoreOS等软路由插件卸载的残留?分享一款软路由高级卸载工具,自定义卸载,轻松解决卸载残留问题

iStoreOS用户看过来!👀 还在被插件包残留困扰吗?本文分享一款“高级卸载”的插件,助你深度清理iStoreOS系统,彻底解决软件卸载不净的痛点,告别频繁恢复出厂设置的烦恼!🚀

XiaoqiangClub的博客 1541

D - Funky Numbers (CodeForces - 192A)

D - Funky Numbers (CodeForces - 192A)  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 inte

benniaoyizhi的博客 1199

CloudCompare 二次开发(36)——非均匀体素降采样

使用CloudCompare与PCL编程实现的非均匀体素降采样。

点云侠的博客 746

codeForces 192A.Funky Numbers(二分)

题意:给你一个数字N,问你是否存在两个数字A,B使得N=A(A+1)2+B(B+1)2N=\frac{A(A+1)}{2}+\frac{B(B+1)}{2} 思路:上面这个式子等价于2N=A(A+1)+B(B+1)2N=A(A+1)+B(B+1),最简单想到的方法就是两重for循环枚举A,B的值从1−n√1-\sqrt{n},这样复杂度为n2n^2,看一下数据范围为1≤n≤1091\leq n\l

张松超的博客 716

硬件工程师入门基础知识(一)基础元器件认识(二)

我们的电路输入一般是只有两种状态,0V 或者是其它的高电平(1.8V,3.3V,5V 等),截止状态一般不用怎么考虑,因为如果让三极管的 Vbe=0,自然就截止了,重要的是饱和状态如何保证。也就是说只要 Rb

小幽余生不加糖 1万+

基于大语言模型的学术论文阅读辅助分析系统的研究与应用

本文提出了一种基于大语言模型的学术论文阅读辅助分析系统PaperMind,旨在解决传统学术阅读方式面临的三大困境:信息定位困难、跨学科知识断层和手动整理耗时。系统采用检索增强生成(RAG)架构,通过PDF文档解析、语义分割、向量嵌入与FAISS向量检索相结合的技术路线,构建了完整的文档处理流水线。实验结果表明,系统在文档加载分割、向量检索与问答生成环节均达到预期性能指标,检索命中率最高达98%。该系统为学术文献智能化处理提供了可复用的技术方案,有效解决了通用大语言模型在学术场景中的幻觉引用、归因能力不足等问

huanghm88的专栏 93

CodeForces - 192A 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...

薄荷糖 344

模型可解释性分析:基于SHAP的深度探索

SHAP模型可解释性分析摘要 本文系统性地介绍了SHAP(SHapley Additive exPlanations)方法在机器学习模型可解释性分析中的应用。SHAP基于博弈论的Shapley值理论,为特征重要性评估提供了统一框架。文章详细阐述了四种核心算法:Kernel SHAP(模型无关方法)、Tree SHAP(针对树模型的高效算法)、Deep SHAP(适用于深度学习)和Linear SHAP(线性模型专用)。通过Python实现展示了从数据准备到SHAP分析的全流程,包括摘要图、依赖图等可视化技术

huanghm88的专栏 611

题目: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 ...

H4ppyD0g的博客 466

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

CodeForces - 192A Funky Numbers 【二分 】

题目链接:http://codeforces.com/problemset/problem/192/A Description As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as, wh...

MengHao的博客 270

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

CodeForces - 192A Funky Numbers ——二分

A. Funky Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output As you very well know, this year's funkies

Lngxling的博客 407

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

【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 ...

xuanweiace的博客 471

Funky Numbers _CF192A

题目 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...

baidu_41907100的博客 329

codeForces 192A-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...

点点滴滴 458

CodeForces 192A 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 tho

CS33sun的博客 490

2013暑假集训B组训练赛第二场

Problem A CodeForces 79A Bus Game  这题先预处理求出三种拿钱方式(0、1、2张100),然后由这三种方式两两组合成9种方式; 然后按照优先选择的规则定义一个小于号,排一下序就ok了。 之后就是逐一的按照排好的顺序取钱。#include #include using namespace std; struct

cx422803902的专栏 934

虚数的本质 | 从旋转变换到复平面的几何直观

…

u013669912的博客 2328

Funky Numbers CodeForces - 192A

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 tho

码农的一亩三分地 398

CodeForces - 192A

A. Funky Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are represe

m0_62529209的博客 418

Triangular numbers

http://codeforces.com/problemset/problem/47/A Triangular numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output st

蚕豆儿 1668

Hust oj 1753 Triangular numbers(三角数)

Triangular numbers Time Limit: 1000 MS Memory Limit: 65536 K Total Submit: 65(43 users) Total Accepted: 43(41 users) Rating: Special Judge: No Description

Tristeza的博客 683
上一篇: Prime Ring Problem
下一篇: HDU 卖水果(map)
donCoder
博客等级 码龄9年 65粉丝 79原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值