@@ -0,0 +1,1152 @@
+package com.github.cschen1205.jp.chap10;%0A%0Aimport java.util.LinkedList;%0Aimport java.util.Queue;%0A%0A/**%0A * Created by memeanalytics on 9/7/17.%0A * Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7 %0A */%0Apublic class Q07 %7B%0A    public static int getKthMagicNumber(int k) %7B%0A        if (k %3C= 0) return 0;%0A      int val = 1;%0A      Queue%3CInteger%3E Q3 = new LinkedList%3CInteger%3E();%0A      Queue%3CInteger%3E Q5 = new LinkedList%3CInteger%3E();%0A      Queue%3CInteger%3E Q7 = new LinkedList%3CInteger%3E();%0A      Q3.add(3);%0A      Q5.add(5); Q7.add(7);%0A      for (--k; k %3E 0; --k) %7B%0A          // We%E2%80%99ve done one iteration already.%0A          val = Math.min(Q3.peek().intValue(),%0A                  Math.min(Q5.peek().intValue(), Q7.peek().intValue()));%0A          if (val == Q7.peek()) %7B%0A              Q7.remove();%0A          %7D else %7B%0A              if (val == Q5.peek()) %7B%0A                  Q5.remove();%0A              %7D else %7B%0A                  // must be from Q3%0A                  Q3.remove();%0A                  Q3.add(val * 3);%0A              %7D%0A              Q5.add(val * 5);%0A          %7D%0A          Q7.add(val * 7);%0A      %7D%0A      return val;%0A    %7D%0A%7D%0A

Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7