def assert_order(r: int, x: int, n: int) -> None:
    """Assert that r is the order of x modulo n."""
    y = x
    for _ in range(1, r):
        assert y % n != 1
        y *= x
    assert y % n == 1
Assert that r is the order of x modulo n.
examples/examples_test.py