Given a number n, write code to find the sum of digits in the factorial of the number. Given n <= 5000
Input : 10 Output : 27 Input : 100 Output : 648
It is not possible to store a number as large as 100! under some data types so, idea is to store extremely large number in vector.
1) Create a vector to store factorial digits and initialize it with 1. 2) One by one multiply numbers from 1 to n to the vector. We use school mathematics for this purpose. 3) Sum all the elements in vector and return the sum.
This article is contributed by Sakshi Tiwari . If you like GeeksforGeeks(We know you do!) and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find the last digit when factorial of A divides factorial of B
- Find the last two digits of Factorial of a given Number
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Smallest number with at least n digits in factorial
- Number of digits in N factorial to the power N
- Find the Largest number with given number of digits and sum of digits
- Find smallest number with given number of digits and sum of digits under given constraints
- Count digits in a factorial | Set 2
- Count digits in a factorial | Set 1
- Minimum digits to be removed to make either all digits or alternating digits same
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Sum of divisors of factorial of a number
- Check if a subarray of length K with sum equal to factorial of a number exists or not
- Find the first natural number whose factorial is divisible by x
- Find maximum power of a number that divides a factorial
- Find the length of factorial of a number in any given base
- Python program to find the factorial of a number using recursion
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number