An improved Euclidean algorithm----the Novice learning algorithm

Source: Internet
Author: User
Tags greatest common divisor

For positive integers A and B, a maximum common factor can be obtained by Euclidean algorithm, and the improved algorithm satisfies the maximum common factor q=xa+yb.

So how do we find A and B?

That's what the book says. So we use the code to get him out, to recommend a book "The Art of Computer.programmer," the first part of the math is really boring the way I choose is appropriate swallowed for this, but for the algorithm described in it is still to Take a closer look at the drip.

For the analysis of the algorithm I go directly to the original book map




#include "stdafx.h"//expanded Euclidean algorithm//For a positive integer A, b  has  m*a+n*b=r  //r for Greatest common divisor this is the improved Euclidean algorithm int _tmain (int argc, char** Grav) {   int m = $, n = 255;int r;int t;int x = 0, x1 = 1, y1 = 0, y = 1;while ((r = m%n)! = 0) {  //change x x1t = x1;x 1 = x;x = t-(int) (m/n) *x; Change y y1t = y1;y1 = Y;y = t-(int) (m/n) *y;       Change m<-n  n<-rm = N;n = r;} printf ("x=%d,y=%d, remainder =%d", x,y,n); return 0;}


An improved Euclidean algorithm----the Novice learning algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.