We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I am able to get the value of k for maximize value of P by using
for (double j=1;j<=N;j++) {
BigDecimal num = new BigDecimal(Math.pow(N, j));
BigDecimal din = new BigDecimal(Math.pow(j, j));
BigDecimal cp = num.divide(din,MathContext.DECIMAL128);
if(cp.compareTo(max) == 1) {
max = cp;
k=j;
}
}
but still I am not getting the D(N) = 2438 for n=100. I checked for smaller numbers like
for n=10 ,D(N)= -15
for n=20 ,D(N)= 10
for n=30 ,D(N)= -29
for n=40 ,D(N)= 326
for n=50, D(N) = 781
Can you please tell me, whether this is correct.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #183: Maximum product of parts
You are viewing a single comment's thread. Return to all comments →
I am able to get the value of k for maximize value of P by using
for (double j=1;j<=N;j++) { BigDecimal num = new BigDecimal(Math.pow(N, j)); BigDecimal din = new BigDecimal(Math.pow(j, j)); BigDecimal cp = num.divide(din,MathContext.DECIMAL128); if(cp.compareTo(max) == 1) { max = cp; k=j; } } but still I am not getting the D(N) = 2438 for n=100. I checked for smaller numbers like for n=10 ,D(N)= -15 for n=20 ,D(N)= 10 for n=30 ,D(N)= -29 for n=40 ,D(N)= 326 for n=50, D(N) = 781
Can you please tell me, whether this is correct.