While iterations

You have to program several functions. Do not use the math module.

1.  Write an integer function @int_root(n)@ that given a natural number
    n returns $\lfloor\sqrt{n}\rfloor$.

2.  Write a function @int_log(a, b)@ that given natural numbers a
    greater than one and b greater than zero returns natural k such that
    a^(k) ≤ b < a^(k + 1).

3.  Write a function @gcd_lcm(a, b)@ that given natural numbers a and b
    such that a ≠ 0 or b ≠ 0 returns the greatest common divisor and the
    least common multiple. Your code has to implement the Euclid’s
    algorithm.

4.  Write a boolean function @is_prime(n)@ that given a natural number n
    returns True if and only if n is prime.

5.  In order to play table games at the casino you need some tokens. Red
    tokens cost 7 euros and yellow tokens cost 4. Write a function
    @buy_tokens(n)@ that given a number n of euros such that n ≥ 20, it
    returns the equivalence in tokens. When several equivalences are
    possible the function returns the one minimizing the total number of
    tokens.

6.  Write a function @inv_factorial(n)@ that given an integer n > 1 it
    returns the number m such that (m − 1)! < n ≤ m!.

Scoring

The first function counts 15 points. Other ones count 17 point each one.

Sample session

Problem information

Author: Jorge Castro

Generation: 2026-01-25T15:48:45.771Z

© Jutge.org, 2006–2026.
https://jutge.org
