Recently, many people have participated in the youdao competition. Among them, many people in the 2nd topic garden have provided procedures. Here I will also talk about my ideas.
Subject requirement: the number of double supercubes is a positive integer that can be split into two different a ^ 3 + B ^ 3 methods, where, B is an integer and 0 <a <= B. For any specified int n, the number of all supercubes less than or equal to n is returned.
Definition
Class: TwiceSuperCubic
Method: count
Parameters: int
Returns: int
Method signature: int count (int n)
(Be sure your method is public)
Constraints
-N value range: 1 to 1,000,000,000 (inclusive)
Examples
0)
1
Returns: 0
1)
1729
Returns: 1
1729 = 1 ^ 3 + 12 ^ 3
1729 = 9 ^ 3 + 10 ^ 3
2)
475574
Returns: 27
After reading a lot of blogs, they are all source programs. I suddenly did not quite understand them. I copied some successful people's code and tried to make improvements. However, during the optimization process, suddenly found: I am engaged in algorithm? Or program?
What is an algorithm? Look at Wikipedia: http://zh.wikipedia.org/w/index.php? Title = % E7 % AE % 97% E6 % B3 % 95 & variant = zh-cn
AlgorithmIt refers to the specific steps and methods required to complete a task. That is to say, given the initial status or input data, the requested or expected termination status or output data can be obtained.
Algorithms often contain repeated steps and comparison or logical judgment. Different algorithms may use different time, space, or efficiency to accomplish the same task. Advantages and disadvantages of an algorithm can be usedSpace complexityAndTime Complexity.
That is, algorithms are the solutions to the problem and use the solutions to solve the existing problems.
Let's look back at the question. I have not found any definition of the double supercube, but the Wikipedia shows two numbers: 1729 and 4104. Both numbers can happen to be written in the form of two cubes, and there are only two types.
1729 = 1 ^ 3 + 12 ^ 3 = 9 ^ 3 + 10 ^ 3 (the first of these series)
4104 = 9 ^ 3 + 15 ^ 3 = 2 ^ 3 + 16 ^ 3
The meaning of the original question is even if we find the number of numbers less than n that can be expressed as the above form.
Many people may think of cubes and formulas first:
A ^ 3 + 3 * a ^ 2 * B + 3 * a * B ^ 2 + B ^ 3 = (a + B) ^ 3
Yes. After simplification, it can be expressed:
A ^ 3 + B ^ 3 = (a + B) * (a ^ 2-a * B + B ^ 2)
First, we should be able to observe that the double supercube N should not be a prime number, and according to the question, there should be only two pairs of approx,
That is
A + B =
A ^ 2-a * B + B ^ 2 = B then ‚
This is a Binary Quadratic System, and there should be only two groups of solutions.
My idea is to traverse the natural numbers smaller than n, then find the numbers with only four dikes (except 1 and itself), and then bring the two groups into the solutions to obtain a and B respectively.
Convert Formula 1 to B = A-a and bring it to formula 2:
3 * a ^ 2-3 * A * a + A ^ 2-B = 0
This is a one-dimensional quadratic equation. If you have any solutions, remember? For junior high school students, Delta> = 0. Today, I am working hard to solve this problem, and I am doing something wrong after simple transformation.
But here we know that for each group of Given A and B, the above equation should have two different Integer Solutions,
Then you have to buy 0.
Delta = (3 * A) ^ 2-4*3 * (A ^ 2-B) = 4 * B-A ^ 2, you must know that the result is an integer solution, so 4 * B-A ^ 2 must be able to square.
So the two solutions a and B are Wikipedia images, but they are borrowed from the form.
At last, the problem becomes an issue of an indefinite equations, and the solutions are all natural numbers.
It can sum up some mathematical constraints and use a computer program to determine the range.
I didn't finally implement this method. I just thought of a solution that could solve the problem and hoped to help you.
First, conduct an algorithm to solve the problem and then convert it into a program.
Postscript:
I believe many people have heard of the art of computer programming. Bill Gates said in 1995, "If you think you are a really good programmer, read the first volume, are you sure you can solve all the problems." "If you can read the entire set of books, please send me your resume ." I have never dared to read this book. This old man is comparable to hawking.