public class Derecursif { public static int f(int n) { ArrayPile pile = new ArrayPile<>(); pile.addFirst(n); int result = 0; while (pile.size() > 0) { n = pile.pollFirst(); switch (n) { case 0: break; case 1: result += 1; break; default: pile.addFirst(n / 2); pile.addFirst(n / 3); break; } } return result; } public static void main(String[] args) { System.out.println(f(150)); } }