{"id":33331,"date":"2024-11-01T09:15:36","date_gmt":"2024-11-01T09:15:36","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=33331"},"modified":"2024-11-01T11:39:09","modified_gmt":"2024-11-01T11:39:09","slug":"java-coding-test-course-finding-the-sum-of-remainders","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/33331\/","title":{"rendered":"Java Coding Test Course, Finding the Sum of Remainders"},"content":{"rendered":"<p>Hello! In today&#8217;s lecture, we will solve an algorithm problem called &#8220;Sum of Remainders&#8221; using Java. This problem involves finding the remainders when a given integer array is divided by a specified number and then summing those remainders. This problem covers important basic concepts for preparing for coding tests.<\/p>\n<h2>Problem Description<\/h2>\n<p>Given an integer array <code>arr<\/code> and an integer <code>m<\/code>, write a function that calculates the remainder of each element in the array when divided by <code>m<\/code> and returns the total sum of those remainders.<\/p>\n<h3>Input<\/h3>\n<ul>\n<li>The first line contains the size of the array <code>n<\/code> (1 \u2264 <code>n<\/code> \u2264 100,000).<\/li>\n<li>The second line contains <code>n<\/code> integers <code>arr[i]<\/code> (1 \u2264 <code>arr[i]<\/code> \u2264 1,000,000) separated by spaces.<\/li>\n<li>The third line contains the integer <code>m<\/code> (1 \u2264 <code>m<\/code> \u2264 1,000,000).<\/li>\n<\/ul>\n<h3>Output<\/h3>\n<p>Print the sum of the remainders after dividing the elements of the array by <code>m<\/code>.<\/p>\n<h3>Example<\/h3>\n<pre>\nInput:\n5\n1 2 3 4 5\n3\n\nOutput:\n15\n<\/pre>\n<h2>Problem-Solving Strategy<\/h2>\n<p>To solve this problem, follow these steps:<\/p>\n<ol>\n<li>After receiving the integer array and integer <code>m<\/code>, calculate the remainders for all elements in the array using <code>m<\/code>.<\/li>\n<li>Add all those remainder values together.<\/li>\n<li>Print the final result.<\/li>\n<\/ol>\n<h2>Implementation<\/h2>\n<p>Now, let&#8217;s implement the above strategy in Java. First, we will write a method to input the array and calculate the remainder for each element when divided by <code>m<\/code>. Below is the Java code that solves this problem:<\/p>\n<pre><code>\nimport java.util.Scanner;\n\npublic class RemainderSum {\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n        \n        \/\/ 1. Input\n        int n = scanner.nextInt(); \/\/ size of the array\n        int[] arr = new int[n];\n        \n        \/\/ Input array elements\n        for (int i = 0; i < n; i++) {\n            arr[i] = scanner.nextInt();\n        }\n        \n        int m = scanner.nextInt(); \/\/ divisor\n\n        \/\/ 2. Calculate sum of remainders\n        long remainderSum = 0; \/\/ variable to store the result\n        for (int i = 0; i < n; i++) {\n            remainderSum += arr[i] % m; \/\/ add remainders\n        }\n\n        \/\/ 3. Print result\n        System.out.println(remainderSum);\n        \n        scanner.close();\n    }\n}\n<\/code><\/pre>\n<h2>Code Explanation<\/h2>\n<ol>\n<li><strong>Input Handling<\/strong>: The <code>Scanner<\/code> class is used to handle input. First, it reads the size of the array <code>n<\/code>, then stores each element in <code>arr<\/code>. Finally, it reads the integer <code>m<\/code> that we want to divide by.<\/li>\n<li><strong>Calculating the Sum of Remainders<\/strong>: After initializing the <code>remainderSum<\/code> variable, a loop is used to add the remainders of each element in the array divided by <code>m<\/code>. The <code>long<\/code> type is used to safely store the sum of large numbers.<\/li>\n<li><strong>Output Result<\/strong>: Finally, the sum of the remainders is printed.<\/li>\n<\/ol>\n<h2>Complexity Analysis<\/h2>\n<p>The time complexity of this programming problem is <strong>O(n)<\/strong>. Due to the length of the array, we need to iterate through all elements in the worst case. The space complexity is <strong>O(1)<\/strong> as there is almost no additional space required.<\/p>\n<h2>Additional Example Tests<\/h2>\n<p>It is also good to consider a few additional test cases after implementing:<\/p>\n<h3>Example 1<\/h3>\n<pre>\nInput:\n3\n5 10 15\n4\n\nOutput:\n6\n<\/pre>\n<h3>Example 2<\/h3>\n<pre>\nInput:\n4\n1 100 10000 1000000\n1\n\nOutput:\n0\n<\/pre>\n<h3>Example 3<\/h3>\n<pre>\nInput:\n5\n0 10 20 30 40\n7\n\nOutput:\n10\n<\/pre>\n<h2>Conclusion<\/h2>\n<p>Today, we solved the \"Sum of Remainders\" problem using Java. Through this example, we learned how to effectively utilize array processing, loops, and remainder calculations. These types of problems can be transformed in various ways, helping to build adaptability. We hope to improve our skills by solving many different algorithm problems in the future!<\/p>\n<p>Thank you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello! In today&#8217;s lecture, we will solve an algorithm problem called &#8220;Sum of Remainders&#8221; using Java. This problem involves finding the remainders when a given integer array is divided by a specified number and then summing those remainders. This problem covers important basic concepts for preparing for coding tests. Problem Description Given an integer array &hellip; <a href=\"https:\/\/atmokpo.com\/w\/33331\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Java Coding Test Course, Finding the Sum of Remainders&#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-33331","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, Finding the Sum of Remainders - \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\/33331\/\" \/>\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, Finding the Sum of Remainders - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello! In today&#8217;s lecture, we will solve an algorithm problem called &#8220;Sum of Remainders&#8221; using Java. This problem involves finding the remainders when a given integer array is divided by a specified number and then summing those remainders. This problem covers important basic concepts for preparing for coding tests. Problem Description Given an integer array &hellip; \ub354 \ubcf4\uae30 &quot;Java Coding Test Course, Finding the Sum of Remainders&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/33331\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:15:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:39:09+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\/33331\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33331\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Java Coding Test Course, Finding the Sum of Remainders\",\"datePublished\":\"2024-11-01T09:15:36+00:00\",\"dateModified\":\"2024-11-01T11:39:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33331\/\"},\"wordCount\":408,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Java Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/33331\/\",\"url\":\"https:\/\/atmokpo.com\/w\/33331\/\",\"name\":\"Java Coding Test Course, Finding the Sum of Remainders - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:15:36+00:00\",\"dateModified\":\"2024-11-01T11:39:09+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33331\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/33331\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/33331\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Coding Test Course, Finding the Sum of Remainders\"}]},{\"@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, Finding the Sum of Remainders - \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\/33331\/","og_locale":"ko_KR","og_type":"article","og_title":"Java Coding Test Course, Finding the Sum of Remainders - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello! In today&#8217;s lecture, we will solve an algorithm problem called &#8220;Sum of Remainders&#8221; using Java. This problem involves finding the remainders when a given integer array is divided by a specified number and then summing those remainders. This problem covers important basic concepts for preparing for coding tests. Problem Description Given an integer array &hellip; \ub354 \ubcf4\uae30 \"Java Coding Test Course, Finding the Sum of Remainders\"","og_url":"https:\/\/atmokpo.com\/w\/33331\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:15:36+00:00","article_modified_time":"2024-11-01T11:39:09+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\/33331\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/33331\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Java Coding Test Course, Finding the Sum of Remainders","datePublished":"2024-11-01T09:15:36+00:00","dateModified":"2024-11-01T11:39:09+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/33331\/"},"wordCount":408,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Java Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/33331\/","url":"https:\/\/atmokpo.com\/w\/33331\/","name":"Java Coding Test Course, Finding the Sum of Remainders - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:15:36+00:00","dateModified":"2024-11-01T11:39:09+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/33331\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/33331\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/33331\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Java Coding Test Course, Finding the Sum of Remainders"}]},{"@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\/33331","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=33331"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33331\/revisions"}],"predecessor-version":[{"id":33332,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33331\/revisions\/33332"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=33331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=33331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=33331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}