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
![](https://oscdn.geek-share.com/Uploads/Images/Content/201909/21/580a7860995163d31c73e7931af49650.png)
, 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
Output
Input
Output
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
![](https://oscdn.geek-share.com/Uploads/Images/Content/201909/21/580a7860995163d31c73e7931af49650.png)
, 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; }
相关文章推荐
- 2013暑假集训B组训练赛第二场 - A Bus Game
- 2013暑假集训B组训练赛第二场 - E Queue at the School
- 2013暑假集训B组训练赛第二场 - C - Purification
- 2013暑假集训B组训练赛第二场
- 2013暑假集训 第二场个人赛总结
- 2013暑假集训B组训练赛第一场
- 暑假集训——个人训练赛04——E题
- CSU-ACM暑假集训基础组训练赛(2) B - Problem B
- 2013 - ECJTU 暑期训练赛第二场-problem-J
- 2013暑假集训 第三场个人赛总结
- 2013暑假集训12级比赛2
- 暑假集训——个人训练赛04——F题
- CSU-ACM暑假集训基础组训练赛(1) A - Problem A
- 暑假集训——个人训练赛04——I题
- 2013暑假江西联合训练赛 -- by jxust_acm 解题报告
- First Bangladeshi Contest 2012-2013 Season[7月12日暑假集训]
- CSU-ACM暑假集训基础组训练赛(2) D - Problem D
- 2013暑假集训 第一场个人赛总结
- CSU-ACM暑假集训基础组训练赛(2) 解题报告
- CSU-ACM暑假集训基础组训练赛(1) B - Problem B