## Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

3 AIM:

Develop a program in C++/Java, based on number theory such as Chinese Remainder or Extended Euclidean Algorithm.

THEORY:

Euclid’s Algorithm: The Greatest Common Divisor (GCD) of two integers is defined as follows: An integer c is called the GCD (a, b) (read as the greatest common divisor of integers a and b if the following 2 conditions hold : 1) C | a^c| b 2) For any common divisor d of a and b, d | c. Rule 2 ensures that the divisor c is the greatest of all the common divisors of a and b. Euclid devised a fairly simple and efficient algorithm to determine the GCF of two integers. The algorithm basically makes use of the division algorithm repeatedly. Let’s find the GCD (a,b), where a and b are integers with a>=b>0 Euclid’s algorithm says to write out the following: a=q1b+r1, b=q2r1+r2, r1=q3r2+r3, . ri=qi+2ri+1+ri+2, rk-1=qk+1rk Euclid’s algorithm says that the GCD (a,b)=rk Consider computing GCD (125, 87) where 0<ri+2<ri+1 where 0<r<b where 0<r2<r1 where 0<r3<r2

the GCD (125. b = r. } GCD = a. r = a – (q*b). } . Pseudo code: GCD (x. y) where x > y > 0 { a = x.20) 125 20 =6*20+5 =4*5 Thus.125 87 38 11 5 =1*87+38 =2*38+11 =3*11+5 =2*5+1 =5*1 Thus. Let’s look at one more. 20) =5. GCD (125. we find that GCD (125. b = y. 87) =1. while (b>0) { q = a/b. a = b.

we get.b) = rk-2 – qkrk-1 Now. .b) = (1+qkqk-1) rk2 – qkrk-3 where 0<rk<rk-1 where 0<r<b where 0<r2<r1 where 0<r3<r2 where 0<ri+2<ri+1 . or GCD (a. rk=rk-2 – qkrk-1. b=q1r1+r2. solve the previous equation for rk-1: rk-1 = rk-3 – qk-1’k-2 And substitute this value into the previous derived equation: GCD (a. Consider writing down the steps of Euclid’s algorithm: a=q1b+r1.Extended Euclidean Algorithm: One of the consequences of the Euclidean algorithm is as follows: Given integers a and b. r1=q3r2+r3.b) = rk-2 – qk(rk-3 – qk-1rk-2) GCD (a.b) Furthermore. rk-2=qkrk-1+rk. rk-1=qk+1rk Consider solving the second to last equation for rk. the extended Euclidean algorithm can be used to find values of x and y to satisfy the equation above. there is always an integral solution to the equation ax+by=gcd(a. ri=qi+2ri+1+ri+2.

from the second to last equation 35=2*15+5 But. Next we can substitute for rk-2 in terms of rk-3 and rk-4. 35 = 135 – 2 * 50 .50): 135 50 35 15 =2*50+35 =1*35+15 =2*15+5 =3*5 Now. finally use the first equation to determine an expression for 35 as a linear combination of 135 and 50.Note that now we have expressed GCD (a. GCD (a. Find integers x and y such that 135x + 50 y =5 Use Euclid’s algorithm to compute GCD(135. so that the GCD (a. . y=8. let’s use the extended Euclidean algorithm to solve the problem: 5=35-2*15. we have that 15=50 – 35.b) will be expressed as a linear combination of a and b as desire. Eventually by continuing this process. from the third to last equation 50 = 1*35+15 Now. 5 = 3 * (135 – 2 * 50 ) – 2 * 50 5 = 3 * 135 – 8 * 50 So.b) can be expressed as the linear combination of rk-3 and rk-4. substitute this value into the previously derived equation: 5 = 35 – 2*(50-35) 5= 135 – 2 * 50 Now. a set of solutions to the equation is x=3.b) as a linear combination of rk-2 and rk-3. Plug this into our last equation.

c’ = c.new2 = 1. c’ = r. new1 = 0. temp1 = old1 – new1*q. old2 = new2. b’ = b. r = b’ % c’.Pseudo code: ComputeInverse(b. new2 = temp2.old2 = 0. r = 2. } return(new2) // b*new1+c*new2 } . old1 = new1. temp2 = old2 – new2*q. c) { old1 = 1. b’ = c’. while (r>1) { q = (b’/c’). new1 = temp1.

.CONCLUSION: Extended Euclidean algorithm has been implemented successfully using JAVA language.

- Introduction to the Design & Analysis of Algorithms 2ND Edition by Anany Levitin
- 3034Chap4.pdf
- Lecture 09
- 10 Euclidean Algorithm
- Contoh Soal
- Eserciziario Di Analisi Matematica 2
- 04 Flowcharts 3
- clab
- unit 1
- Numbers. Divisibility Tests, HCF and LCM
- js_lect1.pdf
- OPTIMAL PRIORITY ASSIGNMENT AND FEASIBILITY OF STATIC PRIORITY TASKS WITH ARBITRARY START TIMES
- L04
- PS 1 2007 Solutions
- 1.1.1.1-1.1.2.1 Open DSA Notes
- 1192_ftp
- 1
- MIT203.pdf for MSc IT
- 50yip
- Desk Checking note
- GSOE Research Projects
- Step to Writing Algorithms
- PEGA Rule Resolution
- v8 models
- Some Famous Problems of the Theory of Numbers and in Particular Warings Problem - Hardy G. H. Godfrey Harold
- Markov Processes Generator
- Business Case
- Chapter1 Problem Solving Techniques
- t05BProgramControlAlgorithms

Skip carousel

- A Survey of Modern Data Classification Techniques
- UT Dallas Syllabus for cs3333.001.11s taught by Jeyakesavan Veerasamy (veerasam)
- Simulation of Single and Multilayer of Artificial Neural Network using Verilog
- Introduction to Multi-Objective Clustering Ensemble
- Determining the shortest path for Travelling Salesman Problem using Nearest Neighbor Algorithm
- tmp904.tmp
- Comparative Analysis of Optimization Algorithms Based on Hybrid Soft Computing Algorithm
- Principles of parallel algorithm models and their objectives
- UT Dallas Syllabus for cs3345.501 05s taught by Greg Ozbirn (ozbirn)
- UT Dallas Syllabus for se3345.502.07f taught by Ivor Page (ivor)
- Analysis & Design Algorithm MCQ'S
- Public Cloud Partition Using Load Status Evaluation and Cloud Division Rules
- UT Dallas Syllabus for cs4349.501 06f taught by Ramaswamy Chandrasekaran (chandra)
- Content-Based Image Retrieval Using Features Extracted From Block Truncation Coding
- UT Dallas Syllabus for cs2305.002 05f taught by Timothy Farage (tfarage)
- tmp8BC6
- UT Dallas Syllabus for opre7313.001.11s taught by Milind Dawande (milind)
- UT Dallas Syllabus for cs6363.002.08s taught by Balaji Raghavachari (rbk)
- Comparison of different Sub-Band Adaptive Noise Canceller with LMS and RLS
- Appraisal of PSO Algorithm over Genetic Algorithm in WSN Using NS2
- The Optimizing Multiple Travelling Salesman Problem Using Genetic Algorithm
- tmpAA72
- tmp5056.tmp
- As 2805.5.1-1992 Electronic Funds Transfer - Requirements for Interfaces Ciphers - Data Encipherment Algorith
- UT Dallas Syllabus for opre7313.001.08f taught by Milind Dawande (milind)
- Hashing Algorithm
- OCR for Gujarati Numeral using Neural Network
- Scheduling Resources In a Hetero-Gene Cloud Using Genetic Algorithm
- A review on Development of novel algorithm by combining Wavelet based Enhanced Canny edge Detection and Adaptive Filtering Method for Human Emotion Recognition
- A Survey on Gesture Recognition

- Mannai Corporation
- CSAT-2011-Reference-Books.doc
- Hydrocarbon vision 2025
- E&P Cos Risk Aversion Means Less Activity
- Hydro Carbon Vision-2025
- [Strategy] RAS 2013 Prelims_ Booklist, Study Material, Approach, Cutoffs, Previous Papers, Syllabus of Rajasthan State & Subordinate Services Combined Competitive Exam - Mrunal
- Oceania
- Dissertation LR Title
- financial management
- NOBEL PRIZE
- open_ssl
- Jurong Refinery

Sign up to vote on this title

UsefulNot usefulClose Dialog## Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

Close Dialog## This title now requires a credit

Use one of your book credits to continue reading from where you left off, or restart the preview.

Loading