{"id":33876,"date":"2024-11-01T09:21:32","date_gmt":"2024-11-01T09:21:32","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=33876"},"modified":"2024-11-01T10:55:28","modified_gmt":"2024-11-01T10:55:28","slug":"c-coding-test-course-extended-euclidean-algorithm","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/33876\/","title":{"rendered":"C# Coding Test Course, Extended Euclidean Algorithm"},"content":{"rendered":"<p><body><\/p>\n<p>Hello, today we will learn about one of the algorithms that frequently appears in coding tests, which is the Extended Euclidean Algorithm. In this article, we will cover the basic principles of the Extended Euclidean Algorithm, examine problems that utilize it, and discuss how to solve these problems using C#.<\/p>\n<h2>1. What is the Extended Euclidean Algorithm?<\/h2>\n<p>The Extended Euclidean Algorithm is an algorithm that finds the following two things for two integers a and b:<\/p>\n<ol>\n<li>It calculates the greatest common divisor (gcd(a, b)) of the two numbers a and b.<\/li>\n<li>It expresses that greatest common divisor in the form of integers x and y that correspond to the ratio of a and b. In other words, it can be represented as <code>gcd(a, b) = ax + by<\/code>.<\/li>\n<\/ol>\n<p>This algorithm is primarily used for solving modular identities or linear equations. Specifically, it plays an important role in cryptography.<\/p>\n<h2>2. Need for the Algorithm<\/h2>\n<p>The extended version of the Euclidean Algorithm is a variant of the Euclidean algorithm that can find the greatest common divisor of two numbers through remainder calculations. However, its usefulness shines in the fact that it not only finds the greatest common divisor but also derives it by combining the two numbers. The x and y obtained through this process can be very useful tools in specific problems.<\/p>\n<h2>3. Implementation of the Algorithm<\/h2>\n<p>First, let&#8217;s define a basic C# function to implement the Extended Euclidean Algorithm. This function accepts two integers a and b as arguments and returns the corresponding greatest common divisor along with the values of x and y.<\/p>\n<pre><code>\nusing System;\n\nclass Program\n{\n    static void Main(string[] args)\n    {\n        int a = 252;\n        int b = 105;\n        \n        var result = ExtendedGCD(a, b);\n        Console.WriteLine($\"gcd: {result.Item1}, x: {result.Item2}, y: {result.Item3}\");\n    }\n\n    static (int, int, int) ExtendedGCD(int a, int b)\n    {\n        if (b == 0)\n        {\n            return (a, 1, 0);\n        }\n\n        var (gcd, x1, y1) = ExtendedGCD(b, a % b);\n        \n        int x = y1;\n        int y = x1 - (a \/ b) * y1;\n\n        return (gcd, x, y);\n    }\n}\n    <\/code><\/pre>\n<h3>3.1 Code Explanation<\/h3>\n<p>The main part of this code is to implement a function called <code>ExtendedGCD<\/code>. This function is called recursively to find the greatest common divisor of two numbers:<\/p>\n<ul>\n<li>As a base case, when b is 0, the gcd is a, and it returns x as 1 and y as 0.<\/li>\n<li>Otherwise, it calls recursively using a and b, and calculates new x and y using the returned values.<\/li>\n<\/ul>\n<h2>4. Example Problem: Finding the GCD and Coefficients<\/h2>\n<p>Now, let&#8217;s solve a specific problem using the Extended Euclidean Algorithm. For example, given two integers a = 252 and b = 105, we will find their greatest common divisor and the coefficients x, y.<\/p>\n<h3>4.1 Problem Definition<\/h3>\n<p>For the given two numbers a and b, find the following:<\/p>\n<ul>\n<li>gcd(a, b)<\/li>\n<li>Find x and y that satisfy <code>gcd(a, b) = ax + by<\/code>.<\/li>\n<\/ul>\n<h3>4.2 Solution Process<\/h3>\n<p>Substituting a = 252 and b = 105 into the given problem, we apply the Extended Euclidean Algorithm. Below is the process:<\/p>\n<ol>\n<li>Call <code>ExtendedGCD(252, 105)<\/code><\/li>\n<li>Here <code>b = 105<\/code>, calling it recursively with <code>ExtendedGCD(105, 252 % 105)<\/code><\/li>\n<li>Continuing to call <code>ExtendedGCD(105, 42)<\/code> where <code>252 % 105 = 42<\/code><\/li>\n<li>Now calling <code>ExtendedGCD(42, 21)<\/code><\/li>\n<li>Finally, when we reach <code>ExtendedGCD(21, 0)<\/code>, it returns the greatest common divisor 21, along with the combination x=1, y=0.<\/li>\n<\/ol>\n<p>During the return process of recursion, the values of x and y are updated one by one, eventually leading us to find <code>gcd(252, 105) = 21<\/code> along with the values of x and y. These values are used to express the greatest common divisor as a linear combination of the given numbers.<\/p>\n<h3>4.3 Results<\/h3>\n<p>The results obtained through this process are as follows:<\/p>\n<ul>\n<li>gcd(252, 105) = 21<\/li>\n<li>With x = -1 and y = 3, it can be represented as <code>21 = 252 * (-1) + 105 * 3<\/code>.<\/li>\n<\/ul>\n<h2>5. Practice Problem<\/h2>\n<p>So far, we have looked at the understanding and implementation of the Extended Euclidean Algorithm. Try to implement the Extended Euclidean Algorithm yourself through the following exercise problem.<\/p>\n<h3>Exercise Problem<\/h3>\n<p>Using the Extended Euclidean Algorithm, find the greatest common divisor and coefficients x, y for the following two integers:<\/p>\n<ul>\n<li>a = 119, b = 544<\/li>\n<\/ul>\n<p>Write your answers and verify them through your implemented C# code!<\/p>\n<h2>6. Conclusion<\/h2>\n<p>Today, we learned about the Extended Euclidean Algorithm. This algorithm is very useful for finding the greatest common divisor of one or more numbers and can express the result as a linear combination, applying to various mathematical problems. This knowledge is extremely important not only in coding tests but also in actual programming. Before moving on to the next advanced topic, it is recommended to review this algorithm once more and practice through various problems.<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello, today we will learn about one of the algorithms that frequently appears in coding tests, which is the Extended Euclidean Algorithm. In this article, we will cover the basic principles of the Extended Euclidean Algorithm, examine problems that utilize it, and discuss how to solve these problems using C#. 1. What is the Extended &hellip; <a href=\"https:\/\/atmokpo.com\/w\/33876\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;C# 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":[90],"tags":[],"class_list":["post-33876","post","type-post","status-publish","format-standard","hentry","category-c-coding-test-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C# 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\/33876\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C# Coding Test Course, Extended Euclidean Algorithm - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello, today we will learn about one of the algorithms that frequently appears in coding tests, which is the Extended Euclidean Algorithm. In this article, we will cover the basic principles of the Extended Euclidean Algorithm, examine problems that utilize it, and discuss how to solve these problems using C#. 1. What is the Extended &hellip; \ub354 \ubcf4\uae30 &quot;C# Coding Test Course, Extended Euclidean Algorithm&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/33876\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:21:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T10:55:28+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=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/33876\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33876\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"C# Coding Test Course, Extended Euclidean Algorithm\",\"datePublished\":\"2024-11-01T09:21:32+00:00\",\"dateModified\":\"2024-11-01T10:55:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33876\/\"},\"wordCount\":647,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"C# Coding Test Tutorials\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/33876\/\",\"url\":\"https:\/\/atmokpo.com\/w\/33876\/\",\"name\":\"C# Coding Test Course, Extended Euclidean Algorithm - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:21:32+00:00\",\"dateModified\":\"2024-11-01T10:55:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33876\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/33876\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/33876\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C# 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":"C# 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\/33876\/","og_locale":"ko_KR","og_type":"article","og_title":"C# Coding Test Course, Extended Euclidean Algorithm - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello, today we will learn about one of the algorithms that frequently appears in coding tests, which is the Extended Euclidean Algorithm. In this article, we will cover the basic principles of the Extended Euclidean Algorithm, examine problems that utilize it, and discuss how to solve these problems using C#. 1. What is the Extended &hellip; \ub354 \ubcf4\uae30 \"C# Coding Test Course, Extended Euclidean Algorithm\"","og_url":"https:\/\/atmokpo.com\/w\/33876\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:21:32+00:00","article_modified_time":"2024-11-01T10:55:28+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":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/33876\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/33876\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"C# Coding Test Course, Extended Euclidean Algorithm","datePublished":"2024-11-01T09:21:32+00:00","dateModified":"2024-11-01T10:55:28+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/33876\/"},"wordCount":647,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["C# Coding Test Tutorials"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/33876\/","url":"https:\/\/atmokpo.com\/w\/33876\/","name":"C# Coding Test Course, Extended Euclidean Algorithm - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:21:32+00:00","dateModified":"2024-11-01T10:55:28+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/33876\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/33876\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/33876\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"C# 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\/33876","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=33876"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33876\/revisions"}],"predecessor-version":[{"id":33877,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33876\/revisions\/33877"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=33876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=33876"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=33876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}