您的位置:首页 > 其它

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

2013-07-27 14:42 363 查看
B - Funky Numbers
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 192A

Description

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

Sample Input

Input
256


Output
YES


Input
512


Output
NO

一开始开了个10^9的数组,结果mle
后来改了还是tle
然后继续怎么都过不了
然后一把乱改,结果改好了。。。= =
心酸;


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const long long MAXN = 1000000005;

int num;
int f[50000];
int n;

void build()
{
n = 0;
int k;
for(int i = 1; k < MAXN; i++)
{
k = i*(i+1)/2;
f[n++]= k;
}
}

int main()
{
build();
n--;
while(~scanf("%d",&num))
{
bool is = 0;
for(int i = 0; f[i] < num; i++)
{
int id = lower_bound(f, f + n,num - f[i]) - f;

if(f[id] == num - f[i])
{
is = true;
break;
}
}
printf("%s\n", is ? "YES" : "NO");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: