Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1078305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:42:13+00:00 2026-05-16T21:42:13+00:00

As an exercise for myself, I’m implementing the Miller-Rabin test. (Working through SICP). I

  • 0

As an exercise for myself, I’m implementing the Miller-Rabin test. (Working through SICP). I understand Fermat’s little theorem and was able to successfully implement that. The part that I’m getting tripped up on in the Miller-Rabin test is this “1 mod n” business. Isn’t 1 mod n (n being some random integer) always 1? So I’m confused at what a “nontrivial square root of 1 modulo n” could be since in my mind “1 mod n” is always 1 when dealing with integer values. What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:42:13+00:00Added an answer on May 16, 2026 at 9:42 pm

    1 is congruent to 9 mod 8 so 3 is a non trivial square root of 1 mod 8.

    what you are working with is not individual numbers, but equivalence sets. [m]n is the set of all numbers x such that x is congruent to m mod n. Any thing that sqaures to any element of this set is a square root of m modulo n.

    given any n, we have the set of integers modulo n which we can write as Zn. this is the set (of sets) [1]n, [2]n, … ,[n]n. Every integer lies in one and only one of those sets. we can define addition and multiplication on this set by [a]n + [b]n = [a + b]n and likewise for multiplication. So a square root of [1]n is a(n element of) [b]n such that [b*b]n = [1]n.

    In practice though, we can conflate m with [m]n and normally choose the unique element, m' of [m]n such that 0 <= m' < n as our ‘representative’ element: this is what we usually think of as the m mod n. but it’s important to keep in mind that we are ‘abusing notation’ as the mathematicians say.

    here’s some (non-idiomatic) python code as I don’t have a scheme interpreter ATM:

    >>> def roots_of_unity(n):
    ...      roots = []
    ...      for i in range(n):
    ...          if i**2 % n == 1:
    ...               roots.append(i)
    ...      return roots
    ... 
    >>> roots_of_unity(4)
    [1, 3]
    >>> roots_of_unity(8)
    [1, 3, 5, 7]
    >>> roots_of_unity(9)
    [1, 8]
    

    So, in particular (looking at the last example), 17 is a root of unity modulo 9. indeed, 17^2 = 289 and 289 % 9 = 1. returning to our previous notation [8]9 = [17]9 and ([17]9)^2 = [1]9

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to teach myself OCaml through Jason Hickey notes and the following exercise
So, while working my way through Scala for the Impatient I found myself wondering:
As an exercise for myself, I was translating a sample program into various languages.
I'm writing a utility for myself, partly as an exercise in learning C# Reflection
As part of an exercise, am implementing an ArrayList which will support Enumerations. Following
i am teaching myself java and i work through the exercises in Thinking in
For a programming exercise I designed for myself, and for use in a pretty
I've started a little project for myself to get more familiar and comfortable with
I've been teaching myself WPF through Sells/Griffiths' Programming WPF, and I've found it a
As an exercise with accessibility and a personal challenge to myself I decided that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.