Central China College preliminaries 1606 Naive

Source: Internet
Author: User

Naive
Time Limit: 3 Sec Memory Limit: 128 MB
Submissions: 316 Solved: 36
Description
Give you a positive integer x, determine whether it is the sum of three positive cubic numbers.

Input
There're several test cases. For each case:
Only one line containing an integer x (1 ≤ x ≤ 10 ^ 6)

Output
For each test case, print "Yes" if it is or "No" if it isn' t.
(See sample for more details)

Sample Input
1
3
10
Sample Output
No
Yes
Yes
HINT
Source
Problem Setter: Zhou

Can a number be expressed as three cubes and three cubes can be the same number?

Ideas:

At the beginning, direct brute-force attacks first input n to determine whether n meets the condition and the result times out.
Later, I changed my mind and first found out the qualified ones. Then I can see that n is not a problem in Xiaoshui.


[Cpp]
# Include <stdio. h>
# Include <string. h>
Int a [105];
Bool flag [1000000 + 10];
Int main ()
{Www.2cto.com
Int I, j, k, n, mid;
For (I = 1; I <= 100; I ++)
A [I] = I * I;
Memset (flag, 0, sizeof (flag ));
For (I = 1; I <= 100; I ++)
For (j = I; j <= 100; j ++)
For (k = j; k <= 100; k ++)
{
Mid = a [I] + a [j] + a [k];
If (mid <= 1000000)
Flag [mid] = 1;
}
While (scanf ("% d", & n )! = EOF)
{
If (flag [n]) printf ("Yes \ n ");
Else printf ("No \ n ");
}

Return 0;
}

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.