1
votes

BUILD A PILE OF CUBES PROBLEM : https://www.codewars.com/kata/5592e3bd57b64d00f3000047/train/java

This is my Solution:

public class ASum {
    
    public static long findNb(long m) {
                double t = Math.sqrt(1+8*Math.sqrt(m));
        double n = (t-1)/2;
                long N = (long)((long)(Math.sqrt(1+8*(long)Math.sqrt(m))-1)/2);
                if(n==N)return N;
                else return -1;
    }   
}

I have used the formula to calculate sum of cubes of natural numbers to get 'n' in terms of 'm' and afterwards I'm checking if n is an integer, if it is then I am returning n otherwise -1.

Input and rendering will be done by codewars compiler, I only need to get my program logic checked.

Please do not add tags for languages that are not relevant to your question.khelwood
Welcome! If you're looking for feedback, you should post to codereview.stackexchange.com. Be sure to review their guidelines first, and make sure your question has all needed detail. Unfortunately this is off-topic here, unless you have a specific issue you need assistance with (and then you need those details documented)David Makogon