{"id":33548,"date":"2024-11-01T09:17:43","date_gmt":"2024-11-01T09:17:43","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=33548"},"modified":"2024-11-01T11:38:00","modified_gmt":"2024-11-01T11:38:00","slug":"java-coding-test-course-extended-euclidean-algorithm","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/33548\/","title":{"rendered":"Java Coding Test Course, Extended Euclidean Algorithm"},"content":{"rendered":"<article>\n<p>In this course, we will learn about the Extended Euclidean Algorithm in detail and solve algorithm problems using it. The Extended Euclidean Algorithm is used to find the greatest common divisor (gcd) of two integers <strong>a<\/strong> and <strong>b<\/strong>, as well as to find integer solutions to the equation <strong>ax + by = gcd(a, b)<\/strong>. This technique is widely used in modern cryptography.<\/p>\n<h2>Problem Description<\/h2>\n<p>Let\u2019s solve the following problem.<\/p>\n<h3>Problem<\/h3>\n<blockquote><p>\n        Given two integers <strong>a<\/strong> and <strong>b<\/strong>, find the values of <strong>x<\/strong> and <strong>y<\/strong> that satisfy <strong>ax + by = gcd(a, b)<\/strong>, and print these values.\n    <\/p><\/blockquote>\n<h2>Understanding the Algorithm<\/h2>\n<p>The Extended Euclidean Algorithm builds upon the basic Euclidean algorithm to calculate <strong>gcd(a, b)<\/strong> and utilizes it to compute the coefficients <strong>x<\/strong> and <strong>y<\/strong>. The basic Euclidean algorithm is used to find the greatest common divisor of two numbers and follows a recursive process as described below:<\/p>\n<pre>\n    gcd(a, 0) = a\n    gcd(0, b) = b\n    gcd(a, b) = gcd(b, a mod b)\n    <\/pre>\n<h2>Extended Euclidean Algorithm<\/h2>\n<p>The Extended Euclidean Algorithm takes a more advanced approach. As mentioned earlier, it derives not only the value of the gcd of two integers but also the integer coefficients for both numbers. The basic idea is as follows:<\/p>\n<ol>\n<li>Use the Euclidean algorithm to recursively calculate <strong>gcd(a, b)<\/strong>.<\/li>\n<li>Track the values of <strong>x<\/strong> and <strong>y<\/strong> at each step and update them as necessary.<\/li>\n<\/ol>\n<h3>Recursive Approach<\/h3>\n<pre>\n    1. First, compute <strong>gcd(a, b)<\/strong>,\n    2. then update <strong>x = y1 - (a \/ b) * x1<\/strong>\n    3. and <strong>y = x1<\/strong>.\n    <\/pre>\n<h2>Problem Solving Process<\/h2>\n<h3>Java Implementation<\/h3>\n<p>Now, let\u2019s implement the above algorithm using Java. The code below accepts two integers <strong>a<\/strong> and <strong>b<\/strong> as input and outputs <strong>gcd(a, b)<\/strong> along with <strong>x<\/strong> and <strong>y<\/strong>.<\/p>\n<pre>\n    <code>\n    public class ExtendedEuclidean {\n        static int[] extendedGcd(int a, int b) {\n            if (b == 0) {\n                return new int[] { a, 1, 0 };\n            }\n            int[] recResult = extendedGcd(b, a % b);\n            int gcd = recResult[0];\n            int x1 = recResult[1];\n            int y1 = recResult[2];\n            int x = y1;\n            int y = x1 - (a \/ b) * y1;\n            return new int[] { gcd, x, y };\n        }\n\n        public static void main(String[] args) {\n            int a = 30; \/\/ The first number to use as input\n            int b = 12; \/\/ The second number to use as input\n            int[] result = extendedGcd(a, b);\n            System.out.println(\"GCD: \" + result[0]);\n            System.out.println(\"x: \" + result[1]);\n            System.out.println(\"y: \" + result[2]);\n        }\n    }\n    <\/code>\n    <\/pre>\n<h2>Code Explanation<\/h2>\n<p>In the above code, the <strong>extendedGcd<\/strong> method recursively returns the greatest common divisor (gcd) and the coefficients <strong>x<\/strong> and <strong>y<\/strong>. Essentially, if <strong>b<\/strong> is 0, it returns <strong>gcd(a, 0) = a<\/strong>. Otherwise, it recursively calculates values using the ratio <strong>gcd(b, a % b)<\/strong>.<\/p>\n<h2>Testing and Results<\/h2>\n<p>Now let\u2019s run the above code and adjust the input values. We can consider several different input examples:<\/p>\n<h3>Test Cases<\/h3>\n<ul>\n<li><strong>a = 30, b = 12<\/strong><\/li>\n<li><strong>a = 56, b = 15<\/strong><\/li>\n<li><strong>a = 101, b = 10<\/strong><\/li>\n<\/ul>\n<p>Let\u2019s check the results for each case.<\/p>\n<h3>Sample Results<\/h3>\n<blockquote>\n<p>Example 1: a = 30, b = 12<\/p>\n<p>GCD: 6<\/p>\n<p>x: 1, y: -2<\/p>\n<\/blockquote>\n<blockquote>\n<p>Example 2: a = 56, b = 15<\/p>\n<p>GCD: 1<\/p>\n<p>x: -4, y: 15<\/p>\n<\/blockquote>\n<blockquote>\n<p>Example 3: a = 101, b = 10<\/p>\n<p>GCD: 1<\/p>\n<p>x: 1, y: -10<\/p>\n<\/blockquote>\n<h2>Conclusion<\/h2>\n<p>In this lecture, we explored the fundamental theory behind the Extended Euclidean Algorithm and the approach to solving problems using it. Through this, we hope you have improved both your mathematical foundations and your Java programming skills. Additionally, we encourage you to implement and test different input values to enhance your understanding of the algorithm.<\/p>\n<h2>Additional Learning Resources<\/h2>\n<p>For more information on the Extended Euclidean Algorithm, please refer to the links below.<\/p>\n<ul>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Extended_Euclidean_algorithm\" target=\"_blank\" rel=\"noopener\">Wikipedia &#8211; Extended Euclidean Algorithm<\/a><\/li>\n<li><a href=\"https:\/\/ocw.mit.edu\/courses\/electrical-engineering-and-computer-science\/6-006-introduction-to-algorithms-fall-2011\/\" target=\"_blank\" rel=\"noopener\">MIT OpenCourseWare &#8211; Introduction to Algorithms<\/a><\/li>\n<\/ul>\n<\/article>\n","protected":false},"excerpt":{"rendered":"<p>In this course, we will learn about the Extended Euclidean Algorithm in detail and solve algorithm problems using it. The Extended Euclidean Algorithm is used to find the greatest common divisor (gcd) of two integers a and b, as well as to find integer solutions to the equation ax + by = gcd(a, b). This &hellip; <a href=\"https:\/\/atmokpo.com\/w\/33548\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Java Coding Test Course, Extended Euclidean Algorithm&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[139],"tags":[],"class_list":["post-33548","post","type-post","status-publish","format-standard","hentry","category-java-coding-test"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java Coding Test Course, Extended Euclidean Algorithm - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/33548\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Coding Test Course, Extended Euclidean Algorithm - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In this course, we will learn about the Extended Euclidean Algorithm in detail and solve algorithm problems using it. The Extended Euclidean Algorithm is used to find the greatest common divisor (gcd) of two integers a and b, as well as to find integer solutions to the equation ax + by = gcd(a, b). This &hellip; \ub354 \ubcf4\uae30 &quot;Java Coding Test Course, Extended Euclidean Algorithm&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/33548\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:17:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:38:00+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/33548\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33548\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Java Coding Test Course, Extended Euclidean Algorithm\",\"datePublished\":\"2024-11-01T09:17:43+00:00\",\"dateModified\":\"2024-11-01T11:38:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33548\/\"},\"wordCount\":443,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Java Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/33548\/\",\"url\":\"https:\/\/atmokpo.com\/w\/33548\/\",\"name\":\"Java Coding Test Course, Extended Euclidean Algorithm - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:17:43+00:00\",\"dateModified\":\"2024-11-01T11:38:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33548\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/33548\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/33548\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Coding Test Course, Extended Euclidean Algorithm\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java Coding Test Course, Extended Euclidean Algorithm - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/33548\/","og_locale":"ko_KR","og_type":"article","og_title":"Java Coding Test Course, Extended Euclidean Algorithm - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In this course, we will learn about the Extended Euclidean Algorithm in detail and solve algorithm problems using it. The Extended Euclidean Algorithm is used to find the greatest common divisor (gcd) of two integers a and b, as well as to find integer solutions to the equation ax + by = gcd(a, b). This &hellip; \ub354 \ubcf4\uae30 \"Java Coding Test Course, Extended Euclidean Algorithm\"","og_url":"https:\/\/atmokpo.com\/w\/33548\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:17:43+00:00","article_modified_time":"2024-11-01T11:38:00+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/33548\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/33548\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Java Coding Test Course, Extended Euclidean Algorithm","datePublished":"2024-11-01T09:17:43+00:00","dateModified":"2024-11-01T11:38:00+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/33548\/"},"wordCount":443,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Java Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/33548\/","url":"https:\/\/atmokpo.com\/w\/33548\/","name":"Java Coding Test Course, Extended Euclidean Algorithm - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:17:43+00:00","dateModified":"2024-11-01T11:38:00+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/33548\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/33548\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/33548\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Java Coding Test Course, Extended Euclidean Algorithm"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=33548"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33548\/revisions"}],"predecessor-version":[{"id":33549,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33548\/revisions\/33549"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=33548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=33548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=33548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}