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 email@example.com. 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.
- Smallest number with at least n digits in factorial
- Number of digits in N factorial to the power N
- Find the first natural number whose factorial is divisible by x
- Find the average of k digits from the beginning and l digits from the end of the given number
- Find the last digit when factorial of A divides factorial of B
- Find maximum power of a number that divides a factorial
- Find the Largest number with given number of digits and sum of digits
- Count digits in a factorial | Set 2
- Count digits in a factorial | Set 1
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Find count of digits in a number that divide the number
- Find the smallest number whose digits multiply to a given number n
- Find maximum number that can be formed using digits of a given number
- Given a number n, find the first k digits of n^n
- Find first and last digits of a number