Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN SCHEME PROGRAMMING LANGUAGE (RACKET) (define +mod (lambda (a b n) (modulo (+ a b) n) )) (define -mod (lambda (a b n) (modulo (-

IN SCHEME PROGRAMMING LANGUAGE (RACKET)

(define +mod

(lambda (a b n)

(modulo (+ a b) n)

))

(define -mod

(lambda (a b n)

(modulo (- a b) n)

))

(define *mod

(lambda (a b n)

(modulo (* a b) n)

Write a procedure exptmod that computes a b (mod n) using repeated squaring. You should use the given modular arithmetic operations, particularly mod, in your solution. Do not use expt or slow-exptmod in your solution.

(define exptmod (lambda (a b n) YOUR-CODE-HERE))

Test your code for at least the following cases:

(exptmod 2 0 10) ; -> 1 (exptmod 2 3 10) ; -> 8 (exptmod 3 4 10) ; -> 1 (exptmod 2 15 100) ; -> 68 (exptmod -5 3 100) ; -> 75

(What I have so far is given below but it doesn't really work.)

(define exptmod

(lambda (a b n)

(cond ((= b 1) 1)

((= b 0) (*mod 1 1 n))

((even? b) (*mod (* a a) (exptmod a (/ b 2) n) n))

(else (*mod (exptmod (* a (- b 1) n) n)))))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions

Question

2. How can competencies be used in employee development?

Answered: 1 week ago