示例#1
0
  /**
   * Runs the algorithm of the "Sieve of Eratosthenes" and count every found prime factor. If the
   * 10001. is found, it is returned.
   *
   * @return the 100001. prime factor
   * @see Sieve#next()
   * @see <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes">Sieve of Eratosthenes @
   *     Wikipedia</a>
   */
  @Override
  public String solve() {

    while (sieve.hasNext() && cnt < 9999) {
      cnt++;
      IO.infoln(cnt + ". prime = " + sieve.next());
    }

    return IO.i2s(sieve.next());
  }
示例#2
0
  /**
   * Calculating the result by running 2 nested loops and adding all products, but ignoring the
   * squares.
   *
   * @return the difference of the sum squares
   */
  @Override
  public String solve() {

    int max = 100, sum = 0;

    for (int i = 1; i <= max; i++) {
      for (int j = 1; j <= max; j++) {
        if (i != j) { // ignore squares
          sum += (i * j);
        }
      }
    }

    return IO.i2s(sum);
  }