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.