public static final Formula empiricalFromMolecular(String formula) {
    int gcd = Integer.MAX_VALUE;
    Formula empiricalFormula = FtHelper.parseFormula(formula);
    List<Integer> subscripts = empiricalFormula.getSubscripts();
    // We'll find GCDs in pairs and store them in tryGCD
    int[] tryGcd = new int[10];
    for (int x = 0; x < subscripts.size() - 1; x++) {
      // First find the initial min and max of the pair.
      int min = Math.min(subscripts.get(x), subscripts.get(x + 1));
      int max = Math.max(subscripts.get(x), subscripts.get(x + 1));
      // Now loop and use the algorithm.
      for (int y = 0; y < 1000; y++) {
        max -= min;
        min = Math.min(max, min);
        max = Math.max(max, min);
        if (max == min) {
          tryGcd[x] = min;
          break;
        }
      }
    }
    // Loop through tryGCD, find the smallest GCD that isn't 0, and set GCD to it.
    for (int candidateGcd : tryGcd) {
      if (candidateGcd != 0) {
        if (candidateGcd < gcd) {
          gcd = candidateGcd;
        }
      }
    }
    // Now that we finally have the GCD, divide the subscripts by it
    // and return the empirical formula.
    List<Integer> newSubscripts = new ArrayList<Integer>();
    for (int subscript : subscripts) {
      newSubscripts.add(subscript / gcd);
    }
    empiricalFormula.setSubscripts(newSubscripts);
    return empiricalFormula;
  }