{"id":35114,"date":"2024-11-01T09:35:40","date_gmt":"2024-11-01T09:35:40","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=35114"},"modified":"2024-11-01T12:43:11","modified_gmt":"2024-11-01T12:43:11","slug":"%ec%bd%94%ed%8b%80%eb%a6%b0-%ec%bd%94%eb%94%a9%ed%85%8c%ec%8a%a4%ed%8a%b8-%ea%b0%95%ec%a2%8c-finding-non-square-numbers","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/35114\/","title":{"rendered":"Kotlin coding test cource, Finding Non-Square Numbers"},"content":{"rendered":"<p><body><\/p>\n<div class=\"section\">\n<p>Hello! In this course, we will delve deeply into algorithm problems that are commonly encountered in coding tests using Kotlin. The topic is &#8216;Finding Non-Perfect Squares.&#8217; The basic idea of this problem is to find all numbers that are not perfect squares (1, 4, 9, 16, etc.) within a given range. We will explore the algorithmic thinking and Kotlin syntax needed to understand and solve this problem.<\/p>\n<\/div>\n<div class=\"section\">\n<h2>Problem Description<\/h2>\n<p>The problem is as follows:<\/p>\n<blockquote><p>\n<strong>Finding Non-Perfect Squares<\/strong><br \/>\n            Write a function to find all numbers that are not perfect squares among natural numbers from 1 to N. <\/p>\n<p><strong>Input<\/strong>: Integer N (1 \u2264 N \u2264 1000)<br \/>\n<strong>Output<\/strong>: List of non-perfect square numbers\n        <\/p><\/blockquote>\n<\/div>\n<div class=\"section\">\n<h2>Problem Analysis<\/h2>\n<p>To solve this problem, the following steps are necessary:<\/p>\n<ul>\n<li>Iterate through all natural numbers from 1 to N.<\/li>\n<li>Devise a method to check if each number is a perfect square.<\/li>\n<li>Store the numbers that are not perfect squares in a list.<\/li>\n<\/ul>\n<p>Perfect squares appear in the form of 1, 4, 9, 16, 25, &#8230; and these numbers are represented as i squared. Therefore, as i starts from 1 and increases to \u221aN, we can store the squared result in a list. After that, we can include the remaining numbers, excluding these perfect squares, in the result list.<\/p>\n<\/div>\n<div class=\"section\">\n<h2>Algorithm Design<\/h2>\n<p>Based on the above process, the following algorithm can be designed:<\/p>\n<ol>\n<li>Create an empty list.<\/li>\n<li>Run a loop from 1 to N.<\/li>\n<li>Determine whether each number is a perfect square.<\/li>\n<li>If it is not a perfect square, add it to the list.<\/li>\n<li>Output the result list.<\/li>\n<\/ol>\n<\/div>\n<div class=\"section\">\n<h2>Kotlin Code Implementation<\/h2>\n<p>Now, let\u2019s implement this algorithm in Kotlin:<\/p>\n<pre><code>fun findNonPerfectSquares(n: Int): List<Int> {\n    val nonPerfectSquares = mutableListOf<Int>()\n    \n    \/\/ Set to store perfect squares\n    val perfectSquares = mutableSetOf<Int>()\n    \n    \/\/ Calculate perfect squares from 1 to n\n    for (i in 1..Math.sqrt(n.toDouble()).toInt()) {\n        perfectSquares.add(i * i)\n    }\n    \n    \/\/ Explore from 1 to N\n    for (i in 1..n) {\n        \/\/ Add to the list if it is not a perfect square\n        if (i !in perfectSquares) {\n            nonPerfectSquares.add(i)\n        }\n    }\n    \n    return nonPerfectSquares\n}<\/Int><\/Int><\/Int><\/code><\/pre>\n<p>In the above code, the <code>findNonPerfectSquares<\/code> function returns a list of numbers that are not perfect squares among natural numbers up to the given N. The use of <code>mutableSetOf<\/code> allows for efficient management of perfect squares, reducing the complexity of the search.<\/p>\n<\/div>\n<div class=\"section\">\n<h2>Code Execution and Results<\/h2>\n<p>Now let&#8217;s test the code we have written and check the results. For example, if we set N to 20 and call the function, we can obtain the following result:<\/p>\n<pre><code>fun main() {\n    val n = 20\n    val result = findNonPerfectSquares(n)\n    println(\"Non-perfect squares from 1 to $n: $result\")\n}<\/code><\/pre>\n<p>When we print the result using the above <code>main<\/code> function, we get the following:<\/p>\n<pre><code>Non-perfect squares from 1 to 20: [2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20]<\/code><\/pre>\n<\/div>\n<div class=\"section\">\n<h2>Complexity Analysis<\/h2>\n<p>Looking at the time complexity of this problem:<\/p>\n<ul>\n<li>For loop to calculate perfect squares: O(\u221aN)<\/li>\n<li>Checking perfect squares in the loop up to N: O(N)<\/li>\n<\/ul>\n<p>Thus, the overall time complexity is O(\u221aN + N) = O(N).<\/p>\n<\/div>\n<div class=\"section\">\n<h2>Conclusion<\/h2>\n<p>In this course, we covered an algorithm problem of finding non-perfect squares. We learned the structure of the problem and how to implement it in Kotlin, as well as the concept of perfect squares and how to manage data efficiently. Since this is a type of problem commonly encountered in coding tests, it is important to approach it as if you are solving a real problem. If you have any questions or additional topics you want to know about, please leave a comment! We look forward to more informative algorithm courses!<\/p>\n<\/div>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello! In this course, we will delve deeply into algorithm problems that are commonly encountered in coding tests using Kotlin. The topic is &#8216;Finding Non-Perfect Squares.&#8217; The basic idea of this problem is to find all numbers that are not perfect squares (1, 4, 9, 16, etc.) within a given range. We will explore the &hellip; <a href=\"https:\/\/atmokpo.com\/w\/35114\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Kotlin coding test cource, Finding Non-Square Numbers&#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":[106],"tags":[],"class_list":["post-35114","post","type-post","status-publish","format-standard","hentry","category----en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Kotlin coding test cource, Finding Non-Square Numbers - \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\/35114\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Kotlin coding test cource, Finding Non-Square Numbers - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello! In this course, we will delve deeply into algorithm problems that are commonly encountered in coding tests using Kotlin. The topic is &#8216;Finding Non-Perfect Squares.&#8217; The basic idea of this problem is to find all numbers that are not perfect squares (1, 4, 9, 16, etc.) within a given range. We will explore the &hellip; \ub354 \ubcf4\uae30 &quot;Kotlin coding test cource, Finding Non-Square Numbers&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/35114\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:35:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T12:43:11+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\/35114\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35114\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Kotlin coding test cource, Finding Non-Square Numbers\",\"datePublished\":\"2024-11-01T09:35:40+00:00\",\"dateModified\":\"2024-11-01T12:43:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35114\/\"},\"wordCount\":476,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Kotlin coding test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/35114\/\",\"url\":\"https:\/\/atmokpo.com\/w\/35114\/\",\"name\":\"Kotlin coding test cource, Finding Non-Square Numbers - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:35:40+00:00\",\"dateModified\":\"2024-11-01T12:43:11+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/35114\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/35114\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/35114\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Kotlin coding test cource, Finding Non-Square Numbers\"}]},{\"@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":"Kotlin coding test cource, Finding Non-Square Numbers - \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\/35114\/","og_locale":"ko_KR","og_type":"article","og_title":"Kotlin coding test cource, Finding Non-Square Numbers - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello! In this course, we will delve deeply into algorithm problems that are commonly encountered in coding tests using Kotlin. The topic is &#8216;Finding Non-Perfect Squares.&#8217; The basic idea of this problem is to find all numbers that are not perfect squares (1, 4, 9, 16, etc.) within a given range. We will explore the &hellip; \ub354 \ubcf4\uae30 \"Kotlin coding test cource, Finding Non-Square Numbers\"","og_url":"https:\/\/atmokpo.com\/w\/35114\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:35:40+00:00","article_modified_time":"2024-11-01T12:43:11+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\/35114\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/35114\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Kotlin coding test cource, Finding Non-Square Numbers","datePublished":"2024-11-01T09:35:40+00:00","dateModified":"2024-11-01T12:43:11+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/35114\/"},"wordCount":476,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Kotlin coding test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/35114\/","url":"https:\/\/atmokpo.com\/w\/35114\/","name":"Kotlin coding test cource, Finding Non-Square Numbers - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:35:40+00:00","dateModified":"2024-11-01T12:43:11+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/35114\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/35114\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/35114\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Kotlin coding test cource, Finding Non-Square Numbers"}]},{"@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\/35114","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=35114"}],"version-history":[{"count":2,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/35114\/revisions"}],"predecessor-version":[{"id":38081,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/35114\/revisions\/38081"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=35114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=35114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=35114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}