codeforces 192A Funky Numbers
2 seconds
256 megabytes
standard input
standard output
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)!
The first input line contains an integer n (1 ≤ n ≤ 109).
Print "YES" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
256
YES
512
NO
In the first sample number
.
In the second sample number 512 can not be represented as a sum of two triangular numbers.
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define f(x) (x)*(x+1)/2
int main()
{ int i=,j=,n;
bool flag=false;
while(~scanf("%d",&n))
{
flag=false;
for(i=;f(i)+f(j)<=n;i++)
{
for(j=i;f(i)+f(j)<=n;j++)
{
if(f(i)+f(j)==n)
{
printf("YES\n");
flag=true;
break;
}
}
if(flag)
break;
j=;
}
if(!flag)
printf("NO\n");
}
return ;
}
codeforces 192A Funky Numbers的更多相关文章
- CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)
传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...
- Codeforces 878 E. Numbers on the blackboard
Codeforces 878 E. Numbers on the blackboard 解题思路 有一种最优策略是每次选择最后面一个大于等于 \(0\) 的元素进行合并,这样做完以后相当于给这个元素乘 ...
- Codeforces 55D. Beautiful numbers(数位DP,离散化)
Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得 ...
- CodeForces 151B Phone Numbers
Phone Numbers Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Sub ...
- codeforces 55D - Beautiful numbers(数位DP+离散化)
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codeforces 165E Compatible Numbers(二进制+逆序枚举)
E. Compatible Numbers time limit per test 4 seconds memory limit per test 256 megabytes input standa ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- CodeForces 165E Compatible Numbers(位运算 + 好题)
wo integers x and y are compatible, if the result of their bitwise "AND" equals zero, that ...
- CodeForces 55D Beautiful numbers
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- Mysql高级之事务
原文:Mysql高级之事务 通俗的说事务: 指一组操作,要么都成功执行,要么都不执行.---->原子性 在所有的操作没有执行完毕之前,其他会话不能够看到中间改变的过程-->隔离性 事务发生 ...
- mediawiki在windows下的安装
mediawiki在windows下的安装 对于刚接触wiki的朋友们来说,配置一个服务器环境,安装并运行mediawiki是一件很麻烦的事情,在这里,我尽量用通俗易懂的语言,介绍mw(mediawi ...
- 【转】 Android项目的mvc模式
MVC (Model-View-Controller):M是指逻辑模型,V是指视图模型,C则是控制器.一个逻辑模型M可以对于多种视图模型V,比如一批统计数据你可以分别用柱状图.饼图V来表示.一种视图模 ...
- Oracle笔试题库之问答题篇-总共60道
1.把表A从表空间TSP1更改成表空间TSP2的方法 解答:alter table A move tablespace TSP2 2.删除表的列: 解答:alert table 表名 drop 列名 ...
- location的使用
<script language="javascript" type="text/javascript"> function setUrl(){ ...
- 验证编辑方法(Edit method)和编辑视图(Edit view)
ASP.NET MVC 5 - 验证编辑方法(Edit method)和编辑视图(Edit view) 在本节中,您将验证电影控制器生成的编辑方法(Edit action methods)和视图.但是 ...
- Printk 标志优先级别
#define KERN_EMERG "<0>" /* 致命级:紧急事件消息,系统崩溃之前提示,表示系统不可用 */# ...
- exit与_exit
一.main函数: 先从程序的执行开始谈起,C程序总是从main函数开始执行,当内核执行C程序时(使用了一个exec函数),在调用main函数前先调用一个特殊的启动例程.可执行程序 文件将此启动例程指 ...
- JS OffsetParent属性
offsetParent 属性返回一个对象的引用,这个对象是距离调用offsetParent的元素最近的(在包含层次中最靠近的),并且是已进行过CSS定位的容器元素. 如果这个容器元素未进行CS ...
- IOS学习之路十四(用TableView做的新闻客户端展示页面)
最近做的也个项目,要做一个IOS的新闻展示view(有图有文字,不用UIwebview,因为数据是用webservice解析的到的json数据),自己一直没有头绪,可后来听一个学长说可以用listvi ...