// The number of descendants after a certain time among // two species: rabbits and degenerated elephants. public class Breeding { public static void main(String[] args) { int n=1; Elephant ellie = new Elephant(); Rabbit bella = new Rabbit(2); while (n > 0) { n = Input.readInt(); System.out.print(ellie.offspring(n) + "\n"); System.out.print(bella.offspring(n) + "\n\n"); } } } abstract class Animal { abstract public int offspring(int months); } // Elephants get one pair of sterile babies every second year. class Elephant extends Animal { public int offspring(int months) { return months / 24; } } // Rabbits get "fertility" pairs of babies every month // from two months age. So do the babies, etc. class Rabbit extends Animal { int fertility; public Rabbit(int f) { fertility = f; } public int offspring(int months) { int cnt = 0; for (int m = 2; m <= months; m++) cnt += fertility + fertility * offspring(months-m); return cnt; } }