Ask Your Question
0

How to write sage program x congruent to -1 (mod (n-1))

asked 2025-04-27 22:59:19 +0200

anonymous user

Anonymous

x congruent to -1 (mod (n-1)) is x+1 = k (n-1)

edit retag flag offensive close merge delete

Comments

It's unclear what you want. My best guess is x = Mod(-1, n-1).

Max Alekseyev gravatar imageMax Alekseyev ( 2025-04-29 15:15:00 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2025-05-03 10:22:51 +0200

slelievre gravatar image

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
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2025-04-27 22:59:19 +0200

Seen: 140 times

Last updated: May 03