Ask Your Question

Revision history [back]

Given x and n, let us test whether x is congruent to -1 modulo n - 1.

For this let us write a function.

The test is based on the reformulation provided in the question.

def is_x_congruent_to_minus_one_modulo_n_minus_one(x, n):
    r"""
    Return whether `x` is congruent to `-1` modulo `n - 1`.
    """
    return ZZ(n - 1).divides(ZZ(x + 1))

Use the function as follows:

sage: is_x_congruent_to_minus_one_modulo_n_minus_one(2, 3)
True
sage: is_x_congruent_to_minus_one_modulo_n_minus_one(4, 3)
False
sage: is_x_congruent_to_minus_one_modulo_n_minus_one(5, 3)
True