Skip to main content
Logo image

PreTeXt Sample Book: Abstract Algebra (SAMPLE ONLY)

Exercises 2.6 Programming Exercises

View Source for exercises
<exercises>
  <title>Programming Exercises</title>
  <exercise>
    <statement>
      <p>
        Write a computer program that will write any decimal number as the sum of distinct powers of 2.
        What is the largest integer that your program will handle?
      </p>
    </statement>
  </exercise>
  <exercise>
    <statement>
      <p>
        Write a computer program to calculate
        <m>a^x \pmod{ n}</m> by the method of repeated squares.
        What are the largest values of <m>n</m> and <m>x</m> that your program will accept?
      </p>
    </statement>
  </exercise>
</exercises>

1.

View Source for exercise
<exercise>
  <statement>
    <p>
      Write a computer program that will write any decimal number as the sum of distinct powers of 2.
      What is the largest integer that your program will handle?
    </p>
  </statement>
</exercise>
Write a computer program that will write any decimal number as the sum of distinct powers of 2. What is the largest integer that your program will handle?

2.

View Source for exercise
<exercise>
  <statement>
    <p>
      Write a computer program to calculate
      <m>a^x \pmod{ n}</m> by the method of repeated squares.
      What are the largest values of <m>n</m> and <m>x</m> that your program will accept?
    </p>
  </statement>
</exercise>
Write a computer program to calculate \(a^x \pmod{ n}\) by the method of repeated squares. What are the largest values of \(n\) and \(x\) that your program will accept?