{"id":18362,"date":"2022-09-07T08:24:53","date_gmt":"2022-09-07T02:54:53","guid":{"rendered":"https:\/\/copyassignment.com\/?p=18362"},"modified":"2022-12-05T16:42:14","modified_gmt":"2022-12-05T11:12:14","slug":"extra-long-factorials-hackerrank-solution","status":"publish","type":"post","link":"https:\/\/copyassignment.com\/extra-long-factorials-hackerrank-solution\/","title":{"rendered":"Extra Long Factorials Hackerrank Solution"},"content":{"rendered":"\n<p>The factorial of a number is defined as the product of all natural numbers up to that number. For example, factorial of 5 or <strong><em>5!<\/em><\/strong> is <strong><em>1 x 2 x 3 x 4 x 5<\/em><\/strong> = <strong><em>120<\/em><\/strong>.<\/p>\n\n\n\n<p>Extra long factorials are factorials of numbers greater than 20. They can be very big with an order of magnitude greater than <strong><em>2^64<\/em><\/strong> which can not be stored even in long long data types in C or C++. Modern languages like Python and JavaScript can easily store them.<\/p>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<h2 class=\"wp-block-heading\">Python Code for Extra Long Factorials Hackerrank Solution<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>def extraLongFactorials(n):\n    # Write your code here\n    fact = 1\n    for num in range(2, n+1):\n        fact *= num\n    print(fact)\n\nif __name__ == '__main__':\n    n = int(input().strip())\n\n    extraLongFactorials(n)<\/code><\/pre>\n\n\n\n<h3 class=\"has-medium-font-size wp-block-heading\">Input<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">25<\/pre>\n\n\n\n<h3 class=\"has-medium-font-size wp-block-heading\">Output<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">15511210043330985984000000<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">JS Code for Extra Long Factorials Hackerrank Solution<\/h2>\n\n\n\n<p>Javascript output large numbers in scientific notation. We will get the output of 25! as 1.5511210043330984e+25. To avoid this we have to use BigInt.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function extraLongFactorials(n) {\n    \/\/ Write your code here\n    var fact = BigInt(1)\n    for(var num=2n; num&lt;=n; num++){\n        fact = fact * num\n    }\n    console.log(fact.toString())\n}\n\nfunction main() {\n    const n = parseInt(readLine().trim(), 10);\n\n    extraLongFactorials(n);\n}<\/code><\/pre>\n\n\n\n<h3 class=\"has-medium-font-size wp-block-heading\">Output<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">15511210043330985984000000<\/pre>\n\n\n\n<h3 class=\"has-medium-font-size wp-block-heading\">HackerRank Snapshot<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"507\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/image-34-1024x507.png\" alt=\"Extra Long Factorials Hackerrank Solution Test Case Passed\" class=\"wp-image-18363 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/image-34-1024x507.png 1024w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/image-34-300x149.png 300w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/image-34-768x381.png 768w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/image-34-1026x508.png 1026w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/image-34-675x335.png 675w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/image-34.png 1132w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/507;\" \/><\/figure>\n\n\n\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-9886351916045880\"\n     crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-format=\"autorelaxed\"\n     data-ad-client=\"ca-pub-9886351916045880\"\n     data-ad-slot=\"7933252109\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<div style=\"text-align:center\" class=\"wp-block-atomic-blocks-ab-button ab-block-button\"><a href=\"https:\/\/copyassignment.com\/top-100-python-projects-with-source-code\/\" class=\"ab-button ab-button-shape-rounded ab-button-size-medium\" style=\"color:#ffffff;background-color:#3373dc\">Best 100+ Python Projects with source code<\/a><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>Also Read:<\/strong><\/p>\n\n\n<ul class=\"wp-block-latest-posts__list is-grid columns-3 wp-block-latest-posts\"><li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/download-1000-projects-all-b-tech-programming-notes-job-resume-interview-guide-and-more-get-your-ultimate-programming-bundle\/\">Download 1000+ Projects, All B.Tech &#038; Programming Notes, Job, Resume &#038; Interview Guide, and More &#8211; Get Your Ultimate Programming Bundle!<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-8-solution-in-python-dictionaries-and-maps\/\">HackerRank Day 8 Solution in Python: Dictionaries and Maps<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-7-solution-in-python-arrays\/\">HackerRank Day 7 Solution in Python: Arrays<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-6-solution-in-python-lets-review\/\">HackerRank Day 6 Solution in Python: Let&#8217;s review<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-5-solution-in-python-loops\/\">HackerRank Day 5 Solution in Python: Loops<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-4-solution-in-python\/\">HackerRank Day 4 Solution in Python: Class vs Instance<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-3-solution-in-python\/\">HackerRank Day 3 Solution in Python: Intro to Conditional Statements<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-2-solution-in-python-operators\/\">HackerRank Day 2 Solution in Python: Operators<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-1-solution-in-python-data-types\/\">HackerRank Day 1 Solution in Python: Data Types<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-0-solution-in-python-hello-world\/\">HackerRank Day 0 Solution in Python: Hello World<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-29-solution-in-python-bitwise-and\/\">HackerRank Day 29 Solution in Python: Bitwise AND<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-28-solution-in-python-regex-patterns-and-intro-to-databases\/\">HackerRank Day 28 Solution in Python: RegEx, Patterns, and Intro to databases<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-27-solution-in-python-testing\/\">HackerRank Day 27 Solution in Python: Testing<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-26-solution-in-python-nested-logic\/\">HackerRank Day 26 Solution in Python: Nested Logic<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-25-solution-in-python-running-time-and-complexity\/\">HackerRank Day 25 Solution in Python: Running Time and Complexity<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-24-solution-in-python-more-linked-lists\/\">HackerRank Day 24 Solution in Python: More Linked Lists<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-23-solution-in-python-bst-level-order-traversal\/\">HackerRank Day 23 Solution in Python: BST Level Order Traversal<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-22-solution-in-python-binary-search-trees\/\">HackerRank Day 22 Solution in Python: Binary Search Trees<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/find-peak-element-leetcode-162\/\">Find Peak Element LeetCode 162<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-20-solution-in-python-sorting\/\">HackerRank Day 20 Solution in Python: Sorting<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-19-solution-in-python-interfaces\/\">HackerRank Day 19 Solution in Python: Interfaces<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-18-solution-in-python-queues-and-stacks\/\">HackerRank Day 18 Solution in Python: Queues and Stacks<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-17-solution-in-python-more-exceptions\/\">HackerRank Day 17 Solution in Python: More Exceptions<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-16-solution-exceptions-string-to-integer\/\">HackerRank Day 16 Solution: Exceptions &#8211; String to Integer<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/explained-allocate-minimum-number-of-pages\/\">Explained: Allocate minimum number of pages<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-15-solution-in-python-linked-list\/\">HackerRank Day 15 Solution in Python: Linked List<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/search-a-2d-matrix-leetcode-74\/\">Search a 2D matrix: leetcode 74<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/maximum-subarray-sum-kadanes-algorithm\/\">Maximum Subarray Sum: Kadane&#8217;s Algorithm<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-13-solution-in-python-abstract-classes\/\">HackerRank Day 13 Solution in Python: Abstract Classes<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/hackerrank-day-14-solution-in-python-scope\/\">HackerRank Day 14 Solution in Python: Scope<\/a><\/li>\n<\/ul>\n\n","protected":false},"excerpt":{"rendered":"<p>The factorial of a number is defined as the product of all natural numbers up to that number. For example, factorial of 5 or 5!&#8230;<\/p>\n","protected":false},"author":62,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,1306],"tags":[],"class_list":["post-18362","post","type-post","status-publish","format-standard","hentry","category-allcategorites","category-competitive-programming","wpcat-22-id","wpcat-1306-id"],"_links":{"self":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/posts\/18362","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/users\/62"}],"replies":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/comments?post=18362"}],"version-history":[{"count":0,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/posts\/18362\/revisions"}],"wp:attachment":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/media?parent=18362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/categories?post=18362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/tags?post=18362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}