Problem 57 of Project Euler is pretty simple forward. It is very easy to see the following relation:
Simple code and was done. Here’s that:
public int getCount(int numberOfExpansions) {
int count = 0;
BigInteger numerator = BigInteger.valueOf(3);
BigInteger denominator = BigInteger.valueOf(2);
while(--numberOfExpansions > 0) {
BigInteger a = denominator.multiply(NumberUtil.BIG_TWO).add(numerator);
BigInteger b = numerator.add(denominator);
numerator = a;
denominator = b;
if(NumberUtil.numberOfDigits(numerator) > NumberUtil.numberOfDigits(denominator)) count++;
}
return count;
}
Popularity: 4% [?]