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;
}