{"id":4652,"date":"2023-12-16T04:00:20","date_gmt":"2023-12-16T04:00:20","guid":{"rendered":"https:\/\/assignment.essayshark.com\/blog\/?p=4652"},"modified":"2024-04-23T07:48:28","modified_gmt":"2024-04-23T07:48:28","slug":"extended-euclidean-algorithm-example","status":"publish","type":"post","link":"https:\/\/assignmentshark.com\/blog\/extended-euclidean-algorithm-example\/","title":{"rendered":"Extended Euclidean Algorithm Example"},"content":{"rendered":"<p>The Euclidean algorithm is an effective algorithm for finding the greatest common divisor of two integers. It is named after the Greek mathematician Euclid, who invented in VII century.<\/p>\n<p>In the most simple case, Euclidean algorithm is applied to a pair of positive integers and generates a new pair consisting of a smaller number, and the modulo between the larger and the smaller number. The process is repeated until the found number will be the greatest common divisor of the original pair.<\/p>\n<p class=\"pls\">The extended Euclidean algorithm also finds such coefficients x and y that:<\/p>\n<p class=\"formula\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/ql-cache\/quicklatex.com-433a27648caedc98e43a41175aafa93a_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#97;&#42;&#120;&#32;&#43;&#32;&#98;&#42;&#121;&#61;&#103;&#99;&#100;&#40;&#97;&#44;&#32;&#98;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"202\" style=\"vertical-align: -5px;\"\/><!--more--><\/p>\n<p><strong>Algorithm<\/strong><\/p>\n<p>To calculate these coefficients we should derive formulas that change them during the transition from pair <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/ql-cache\/quicklatex.com-8e492dcccf14a8590a00ec5d5a58154e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#40;&#97;&#44;&#32;&#98;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"41\" style=\"vertical-align: -5px;\"\/> to pair <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/ql-cache\/quicklatex.com-aaf23f0a26c331db9bc0e72622ad2e03_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#40;&#98;&#92;&#37;&#97;&#44;&#32;&#97;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"21\" width=\"68\" style=\"vertical-align: -5px;\"\/> (% means the modulo operation)<\/p>\n<p>So, we have a solution <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/ql-cache\/quicklatex.com-c9d439cd62f9bb425c7a879a83a3f7b5_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#40;&#120;&#49;&#44;&#32;&#121;&#49;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"64\" style=\"vertical-align: -5px;\"\/> for the new pair <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/ql-cache\/quicklatex.com-aaf23f0a26c331db9bc0e72622ad2e03_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#40;&#98;&#92;&#37;&#97;&#44;&#32;&#97;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"21\" width=\"68\" style=\"vertical-align: -5px;\"\/>:<\/p>\n<p class=\"formula\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/ql-cache\/quicklatex.com-a658c7ac2e494b64b6a03aeb8d870a4f_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#40;&#98;&#92;&#37;&#97;&#41;&#42;&#120;&#95;&#49;&#32;&#43;&#32;&#97;&#42;&#121;&#95;&#49;&#32;&#61;&#32;&#103;&#44;\" title=\"Rendered by QuickLaTeX.com\" height=\"21\" width=\"204\" style=\"vertical-align: -5px;\"\/><\/p>\n<p>And now we want to find a solution <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/ql-cache\/quicklatex.com-4aa76c25fe5f15339d4c2aaf519a8731_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#40;&#120;&#44;&#32;&#121;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"44\" style=\"vertical-align: -5px;\"\/> for our pair <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/ql-cache\/quicklatex.com-8e492dcccf14a8590a00ec5d5a58154e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#40;&#97;&#44;&#32;&#98;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"41\" style=\"vertical-align: -5px;\"\/>:<\/p>\n<p class=\"formula\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/ql-cache\/quicklatex.com-6258f4d17c74b68d93d82a2f4a876e61_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#97;&#42;&#120;&#32;&#43;&#32;&#98;&#42;&#121;&#32;&#61;&#32;&#103;&#46;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"144\" style=\"vertical-align: -4px;\"\/><\/p>\n<p>To do this we should transform <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/ql-cache\/quicklatex.com-ec95ea42d472f8f7b07768cba76d2a3a_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#98;&#92;&#37;&#97;\" title=\"Rendered by QuickLaTeX.com\" height=\"17\" width=\"36\" style=\"vertical-align: -1px;\"\/>:<\/p>\n<p class=\"formula\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/ql-cache\/quicklatex.com-763ef4a2316cfd9003a92647ca860a1a_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#98;&#92;&#37;&#97;&#32;&#61;&#32;&#98;&#32;&#45;&#32;&#91;&#92;&#102;&#114;&#97;&#99;&#123;&#98;&#125;&#123;&#97;&#125;&#93;&#42;&#97;\" title=\"Rendered by QuickLaTeX.com\" height=\"26\" width=\"148\" style=\"vertical-align: -7px;\"\/><\/p>\n<p>Substitute this in the expression below and get:<\/p>\n<p class=\"formula\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/ql-cache\/quicklatex.com-367e370e075ec521fece1cca497ea99d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#103;&#32;&#61;&#32;&#40;&#98;&#92;&#37;&#97;&#41;&#42;&#120;&#95;&#49;&#32;&#43;&#32;&#97;&#42;&#121;&#95;&#49;&#32;&#61;&#32;&#40;&#98;&#32;&#45;&#32;&#91;&#92;&#102;&#114;&#97;&#99;&#123;&#98;&#125;&#123;&#97;&#125;&#93;&#42;&#97;&#41;&#42;&#120;&#95;&#49;&#32;&#43;&#32;&#97;&#42;&#121;&#95;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"26\" width=\"438\" style=\"vertical-align: -7px;\"\/><\/p>\n<p>Transform:<\/p>\n<p class=\"formula\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/ql-cache\/quicklatex.com-194945d4c515e597b221a4b71bee8c01_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#103;&#32;&#61;&#32;&#98;&#42;&#120;&#95;&#49;&#32;&#43;&#32;&#97;&#32;&#42;&#32;&#40;&#121;&#95;&#49;&#32;&#45;&#32;&#91;&#92;&#102;&#114;&#97;&#99;&#123;&#98;&#125;&#123;&#97;&#125;&#93;&#42;&#120;&#95;&#49;&#32;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"26\" width=\"258\" style=\"vertical-align: -7px;\"\/><\/p>\n<p>So we get the needed expression:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/ql-cache\/quicklatex.com-ff0cbeaf25c5db768e80b7161a7ff7ce_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#108;&#101;&#102;&#116;&#92;&#123;&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#109;&#97;&#116;&#114;&#105;&#120;&#125;&#32;&#120;&#32;&#61;&#32;&#121;&#95;&#49;&#32;&#45;&#32;&#91;&#92;&#102;&#114;&#97;&#99;&#123;&#98;&#125;&#123;&#97;&#125;&#93;&#42;&#120;&#95;&#49;&#44; &#92;&#92;&#121;&#32;&#61;&#32;&#120;&#95;&#49;  &#92;&#101;&#110;&#100;&#123;&#109;&#97;&#116;&#114;&#105;&#120;&#125;&#92;&#114;&#105;&#103;&#104;&#116;&#46;\" title=\"Rendered by QuickLaTeX.com\" height=\"50\" width=\"162\" style=\"vertical-align: -19px;\"\/><\/p>\n<p>C# implementation:<\/p>\n<p style=\"margin: 0 auto; max-width: 400px;\"><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/extended-euclidean-algorithm-1.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-4716\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/extended-euclidean-algorithm-1.png\" alt=\"extended-euclidean-algorithm-1\" width=\"100%\" height=\"auto\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/extended-euclidean-algorithm-1.png 450w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/extended-euclidean-algorithm-1-300x134.png 300w\" sizes=\"(max-width: 450px) 100vw, 450px\" \/><\/a><\/p>\n<p style=\"margin: 0 auto; max-width: 400px;\"><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/extended-euclidean-algorithm-2.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-4718\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/extended-euclidean-algorithm-2.png\" alt=\"extended-euclidean-algorithm-2\" width=\"100%\" height=\"auto\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/extended-euclidean-algorithm-2.png 450w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/extended-euclidean-algorithm-2-300x134.png 300w\" sizes=\"(max-width: 450px) 100vw, 450px\" \/><\/a><\/p>\n<p>Too big values:<\/p>\n<p style=\"margin: 0 auto; max-width: 500px;\"><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/extended-euclidean-algorithm-3.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-4720\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/extended-euclidean-algorithm-3.png\" alt=\"extended-euclidean-algorithm-3\" width=\"100%\" height=\"auto\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/extended-euclidean-algorithm-3.png 561w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/extended-euclidean-algorithm-3-300x112.png 300w\" sizes=\"(max-width: 561px) 100vw, 561px\" \/><\/a><\/p>\n<p>Code listing:<\/p>\n<p><strong>EuclidExtended.cs:<\/strong><\/p>\n<p>[code language=&#8221;csharp&#8221;]<br \/>\nusing System;<\/p>\n<p>namespace EuclidExtended<br \/>\n{<br \/>\n    public class EuclidExtended<br \/>\n    {<br \/>\n        private long a, b;<\/p>\n<p>        public EuclidExtended(long a, long b)<br \/>\n        {<br \/>\n            this.a = a;<br \/>\n            this.b = b;<br \/>\n        }<\/p>\n<p>        public EuclidExtendedSolution solve()<br \/>\n        {<br \/>\n            long x0 = 1, xn = 1, y0 = 0, yn = 0, x1 = 0, y1 = 1, f, r = a % b;<\/p>\n<p>            while (r &gt; 0)<br \/>\n            {<br \/>\n                f = a \/ b;<br \/>\n                xn = x0 &#8211; f * x1;<br \/>\n                yn = y0 &#8211; f * y1;<\/p>\n<p>                x0 = x1;<br \/>\n                y0 = y1;<br \/>\n                x1 = xn;<br \/>\n                y1 = yn;<br \/>\n                a = b;<br \/>\n                b = r;<br \/>\n                r = a % b;<br \/>\n            }<\/p>\n<p>            return new EuclidExtendedSolution(xn, yn, b);<br \/>\n        }<\/p>\n<p>    }<br \/>\n}<br \/>\n[\/code]<\/p>\n<p>Code listing:<\/p>\n<p><strong>EuclidExtended.cs:<\/strong><\/p>\n<p>[code language=&#8221;csharp&#8221;]<br \/>\nusing System;<\/p>\n<p>namespace EuclidExtended<br \/>\n{<br \/>\n    public class EuclidExtended<br \/>\n    {<br \/>\n        private long a, b;<\/p>\n<p>        public EuclidExtended(long a, long b)<br \/>\n        {<br \/>\n            this.a = a;<br \/>\n            this.b = b;<br \/>\n        }<\/p>\n<p>        public EuclidExtendedSolution solve()<br \/>\n        {<br \/>\n            long x0 = 1, xn = 1, y0 = 0, yn = 0, x1 = 0, y1 = 1, f, r = a % b;<\/p>\n<p>            while (r &gt; 0)<br \/>\n            {<br \/>\n                f = a \/ b;<br \/>\n                xn = x0 &#8211; f * x1;<br \/>\n                yn = y0 &#8211; f * y1;<\/p>\n<p>                x0 = x1;<br \/>\n                y0 = y1;<br \/>\n                x1 = xn;<br \/>\n                y1 = yn;<br \/>\n                a = b;<br \/>\n                b = r;<br \/>\n                r = a % b;<br \/>\n            }<\/p>\n<p>            return new EuclidExtendedSolution(xn, yn, b);<br \/>\n        }<\/p>\n<p>    }<br \/>\n}<br \/>\n[\/code]<\/p>\n<p><strong>EuclidExtendedSolution.cs:<\/strong><\/p>\n<p>[code language=&#8221;csharp&#8221;]<br \/>\nusing System;<\/p>\n<p>namespace EuclidExtended<br \/>\n{<br \/>\n    public class EuclidExtendedSolution<br \/>\n    {<br \/>\n        private long x, y, d;<\/p>\n<p>        public long X<br \/>\n        {<br \/>\n            get<br \/>\n            {<br \/>\n                return this.x;<br \/>\n            }<br \/>\n        }<\/p>\n<p>        public long Y<br \/>\n        {<br \/>\n            get<br \/>\n            {<br \/>\n                return this.y;<br \/>\n            }<br \/>\n        }<\/p>\n<p>        public long D<br \/>\n        {<br \/>\n            get<br \/>\n            {<br \/>\n                return this.d;<br \/>\n            }<br \/>\n        }<\/p>\n<p>        public EuclidExtendedSolution(long x, long y, long d)<br \/>\n        {<br \/>\n            this.x = x;<br \/>\n            this.y = y;<br \/>\n            this.d = d;<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>[\/code]<\/p>\n<p><strong>Form1.Designer.cs:<\/strong><\/p>\n<p>[code language=&#8221;csharp&#8221;]<br \/>\nnamespace EuclidExtended<br \/>\n{<br \/>\n    partial class Form1<br \/>\n    {<br \/>\n        \/\/\/<\/p>\n<p>        \/\/\/ &lt;summary&gt;<br \/>\n        \/\/\/ Required designer variable.<br \/>\n        \/\/\/ &lt;\/summary&gt;<\/p>\n<p>        private System.ComponentModel.IContainer components = null;<\/p>\n<p>        \/\/\/<\/p>\n<p>        \/\/\/ &lt;summary&gt;<br \/>\n        \/\/\/ Clean up any resources being used.<br \/>\n        \/\/\/ &lt;\/summary&gt;<\/p>\n<p>        \/\/\/ &lt;param name=&quot;disposing&quot;&gt;true if managed resources should be disposed; otherwise, false.&lt;\/param&gt;<br \/>\n        protected override void Dispose(bool disposing)<br \/>\n        {<br \/>\n            if (disposing &amp;&amp; (components != null))<br \/>\n            {<br \/>\n                components.Dispose();<br \/>\n            }<br \/>\n            base.Dispose(disposing);<br \/>\n        }<\/p>\n<p>        #region Windows Form Designer generated code<\/p>\n<p>        \/\/\/<\/p>\n<p>        \/\/\/ &lt;summary&gt;<br \/>\n        \/\/\/ Required method for Designer support &#8211; do not modify<br \/>\n        \/\/\/ the contents of this method with the code editor.<br \/>\n        \/\/\/ &lt;\/summary&gt;<\/p>\n<p>        private void InitializeComponent()<br \/>\n        {<br \/>\n            this.lblA = new System.Windows.Forms.Label();<br \/>\n            this.txtA = new System.Windows.Forms.TextBox();<br \/>\n            this.txtB = new System.Windows.Forms.TextBox();<br \/>\n            this.lblB = new System.Windows.Forms.Label();<br \/>\n            this.btnCalculate = new System.Windows.Forms.Button();<br \/>\n            this.lblResult = new System.Windows.Forms.Label();<br \/>\n            this.SuspendLayout();<br \/>\n            \/\/<br \/>\n            \/\/ lblA<br \/>\n            \/\/<br \/>\n            this.lblA.AutoSize = true;<br \/>\n            this.lblA.Location = new System.Drawing.Point(33, 28);<br \/>\n            this.lblA.Name = &quot;lblA&quot;;<br \/>\n            this.lblA.Size = new System.Drawing.Size(16, 13);<br \/>\n            this.lblA.TabIndex = 0;<br \/>\n            this.lblA.Text = &quot;a:&quot;;<br \/>\n            this.lblA.Click += new System.EventHandler(this.label1_Click);<br \/>\n            \/\/<br \/>\n            \/\/ txtA<br \/>\n            \/\/<br \/>\n            this.txtA.Location = new System.Drawing.Point(55, 25);<br \/>\n            this.txtA.Name = &quot;txtA&quot;;<br \/>\n            this.txtA.Size = new System.Drawing.Size(100, 20);<br \/>\n            this.txtA.TabIndex = 1;<br \/>\n            this.txtA.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtA_KeyDown);<br \/>\n            \/\/<br \/>\n            \/\/ txtB<br \/>\n            \/\/<br \/>\n            this.txtB.Location = new System.Drawing.Point(55, 63);<br \/>\n            this.txtB.Name = &quot;txtB&quot;;<br \/>\n            this.txtB.Size = new System.Drawing.Size(100, 20);<br \/>\n            this.txtB.TabIndex = 3;<br \/>\n            this.txtB.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtB_KeyDown);<br \/>\n            \/\/<br \/>\n            \/\/ lblB<br \/>\n            \/\/<br \/>\n            this.lblB.AutoSize = true;<br \/>\n            this.lblB.Location = new System.Drawing.Point(33, 66);<br \/>\n            this.lblB.Name = &quot;lblB&quot;;<br \/>\n            this.lblB.Size = new System.Drawing.Size(16, 13);<br \/>\n            this.lblB.TabIndex = 2;<br \/>\n            this.lblB.Text = &quot;b:&quot;;<br \/>\n            \/\/<br \/>\n            \/\/ btnCalculate<br \/>\n            \/\/<br \/>\n            this.btnCalculate.Location = new System.Drawing.Point(36, 108);<br \/>\n            this.btnCalculate.Name = &quot;btnCalculate&quot;;<br \/>\n            this.btnCalculate.Size = new System.Drawing.Size(119, 23);<br \/>\n            this.btnCalculate.TabIndex = 4;<br \/>\n            this.btnCalculate.Text = &quot;Calculate&quot;;<br \/>\n            this.btnCalculate.UseVisualStyleBackColor = true;<br \/>\n            this.btnCalculate.Click += new System.EventHandler(this.btnCalculate_Click);<br \/>\n            \/\/<br \/>\n            \/\/ lblResult<br \/>\n            \/\/<br \/>\n            this.lblResult.Font = new System.Drawing.Font(&quot;Microsoft Sans Serif&quot;, 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));<br \/>\n            this.lblResult.Location = new System.Drawing.Point(241, 27);<br \/>\n            this.lblResult.Name = &quot;lblResult&quot;;<br \/>\n            this.lblResult.Size = new System.Drawing.Size(193, 104);<br \/>\n            this.lblResult.TabIndex = 5;<br \/>\n            this.lblResult.Text = &quot;ax + by = 1&quot;;<br \/>\n            \/\/<br \/>\n            \/\/ Form1<br \/>\n            \/\/<br \/>\n            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);<br \/>\n            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;<br \/>\n            this.ClientSize = new System.Drawing.Size(446, 166);<br \/>\n            this.Controls.Add(this.lblResult);<br \/>\n            this.Controls.Add(this.btnCalculate);<br \/>\n            this.Controls.Add(this.txtB);<br \/>\n            this.Controls.Add(this.lblB);<br \/>\n            this.Controls.Add(this.txtA);<br \/>\n            this.Controls.Add(this.lblA);<br \/>\n            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;<br \/>\n            this.MaximizeBox = false;<br \/>\n            this.Name = &quot;Form1&quot;;<br \/>\n            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;<br \/>\n            this.Text = &quot;Euclid\\&#8217;s Extended Algorithm&quot;;<br \/>\n            this.ResumeLayout(false);<br \/>\n            this.PerformLayout();<\/p>\n<p>        }<\/p>\n<p>        #endregion<\/p>\n<p>        private System.Windows.Forms.Label lblA;<br \/>\n        private System.Windows.Forms.TextBox txtA;<br \/>\n        private System.Windows.Forms.TextBox txtB;<br \/>\n        private System.Windows.Forms.Label lblB;<br \/>\n        private System.Windows.Forms.Button btnCalculate;<br \/>\n        private System.Windows.Forms.Label lblResult;<br \/>\n    }<br \/>\n}<br \/>\n[\/code]<\/p>\n<p><strong>Form1.cs:<\/strong><\/p>\n<p>[code language=&#8221;csharp&#8221;]<br \/>\nusing System;<br \/>\nusing System.Collections.Generic;<br \/>\nusing System.ComponentModel;<br \/>\nusing System.Data;<br \/>\nusing System.Drawing;<br \/>\nusing System.Linq;<br \/>\nusing System.Text;<br \/>\nusing System.Threading.Tasks;<br \/>\nusing System.Windows.Forms;<\/p>\n<p>namespace EuclidExtended<br \/>\n{<br \/>\n    public partial class Form1 : Form<br \/>\n    {<br \/>\n        public Form1()<br \/>\n        {<br \/>\n            InitializeComponent();<br \/>\n        }<\/p>\n<p>        private void label1_Click(object sender, EventArgs e)<br \/>\n        {<\/p>\n<p>        }<\/p>\n<p>        private void btnCalculate_Click(object sender, EventArgs e)<br \/>\n        {<br \/>\n            performSolving();<br \/>\n        }<\/p>\n<p>        private void txtA_KeyDown(object sender, KeyEventArgs e)<br \/>\n        {<br \/>\n            if (e.KeyCode == Keys.Return)<br \/>\n            {<br \/>\n                txtB.Focus();<br \/>\n            }<br \/>\n        }<\/p>\n<p>        private void txtB_KeyDown(object sender, KeyEventArgs e)<br \/>\n        {<br \/>\n            if (e.KeyCode == Keys.Return)<br \/>\n            {<br \/>\n                performSolving();<br \/>\n            }<br \/>\n        }<\/p>\n<p>        private void performSolving()<br \/>\n        {<br \/>\n            try<br \/>\n            {<br \/>\n                long a = long.Parse(txtA.Text);<br \/>\n                long b = long.Parse(txtB.Text);<\/p>\n<p>                EuclidExtended ee = new EuclidExtended(a, b);<br \/>\n                EuclidExtendedSolution result = ee.solve();<\/p>\n<p>                lblResult.Text = string.Format(&quot;d = {0} {1}x = {2} {1}y = {3}&quot;, result.D, Environment.NewLine, result.X, result.Y);<br \/>\n            }<br \/>\n            catch (Exception ex)<br \/>\n            {<br \/>\n                String message = string.Format(&quot;Something is wrong:{0}\\&quot;{1}\\&quot;&quot;, Environment.NewLine, ex.Message);<br \/>\n                MessageBox.Show(message, &quot;Error :\/&quot;, MessageBoxButtons.OK, MessageBoxIcon.Error);<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n}<br \/>\n[\/code]<\/p>\n<h2>Math and Accounting Homework Assistance<\/h2>\n<blockquote><p><em>We hope our Extended Euclidean algorithm example will help you to complete your task. It was prepared by a well-qualified expert that is knowledgeable in the topic. If you are having difficulties with tasks that concern Extended Euclidian algorithm you can apply to AssignmentShark for help. <\/em><\/p>\n<p><em>What exactly can we do for you? Our experienced experts will help you to cope with your assignment quickly and easily. Getting <a href=\"https:\/\/assignmentshark.com\/\" target=\"_blank\" rel=\"noopener\">help with assignments<\/a> from us is absolutely safe. We care about your privacy. If you need help right now just contact us and get an assignment of the same quality or even better! Service is available 24\/7 no matter whether you need urgent <a href=\"https:\/\/assignmentshark.com\/accounting-homework-help.html\" target=\"_blank\" rel=\"noopener\">help with accounting assignment<\/a>, or a detailed calculation of a monthly project!<\/em><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>The Euclidean algorithm is an effective algorithm for finding the greatest common divisor of two integers. It is named after the Greek mathematician Euclid, who invented in VII century. In the most simple case, Euclidean algorithm is applied to a pair of positive integers and generates a new pair consisting of a smaller number, and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53,35],"tags":[],"class_list":["post-4652","post","type-post","status-publish","format-standard","hentry","category-it","category-samples"],"_links":{"self":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/4652","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/comments?post=4652"}],"version-history":[{"count":48,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/4652\/revisions"}],"predecessor-version":[{"id":13507,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/4652\/revisions\/13507"}],"wp:attachment":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/media?parent=4652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/categories?post=4652"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/tags?post=4652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}