How to write sage program x congruent to -1 (mod (n-1))
x congruent to -1 (mod (n-1)) is x+1 = k (n-1)
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
Asked: 2025-04-27 22:59:19 +0200
Seen: 140 times
Last updated: May 03
It's unclear what you want. My best guess is
x = Mod(-1, n-1)
.