Forum

Post 19.05.2009   # 1
Subject CodeFu 2009 Round 2 - Problem 100
100. Total Cubes

Input constraint for N is: 1<=N<=1000000.

Since 100*100*100 = 1000000, you only have to check if the cubes of the numbers between 1 and 100 are in the given range.

public class TotalCubes {

public int howMany(int A, int B) {
int total = 0;
for (int i = 1; i <= 100; ++i) {
if (i*i*i >= A && i*i*i <= B) {
++total;
}
}
return total;
}
}

bilievsk is offline Reply

Please login to post reply.