Saturday, May 29, 2010

Problem 29: How many distinct terms are in the sequence generated by a^(b) for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100?

Too easy.

let problem29a =
    seq {for a in 2I..100I do for b in 2..100 do yield bigint.Pow(a,b)}
    |> Seq.distinct 
    |> Seq.length

1 comment:

  1. import static java.math.BigInteger.valueOf;
    import static java.util.Arrays.stream;
    public static void main(String[] args) {

    int max = 100, count = 0;
    String[] field = new String[(max - 1) * (max - 1)];
    for (int a = 2; a <= max; a++)
    for (int b = 2; b <= max; b++) {
    String term = valueOf(a).pow(b).toString();
    if (stream(field).noneMatch(term::equals)) field[count++] = term;
    }
    System.out.printf("Für die Obergrenze %d für a und b ergeben sich %d einzigartige Ergebnisse.", max, count);
    }
    }

    ReplyDelete