Netease-youdao subject-dual supercube-Topcoder-issue (500 points)

Source: Internet
Author: User

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

 

 

 

 

 

Code
Public static class TwiceSuperCubic
{
Public static int count (int n)
{
Int r = 0;
Int f =-1;
If (n> 0 & n <= 1000000000)
{
For (int I = 1; I <= n; I ++)
{
F = 0;
Double sq = Math. Pow (I, 1f/3 );
For (int k = 1; k <sq; k ++)
{
If (I> k * k)
{
Int m = k;
For (; m <sq; m ++)
{
If (I> m * m)
{
If (I = (m * m + k * k ))
{
F ++;
}
}
}
}
}
If (f> 1)
{
R ++;
}
}
}
Return r;
}

}

 

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.