Skip to content
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions The sum of all factorials of n!
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Following are the steps for an efficient solution:

n! can be represented as :- n! = (a1^p1) (a2^p2)x...(ak^pk).

where ak is the prime divisor lesser than n and pk is the highest power which can divide n!.

Through sieve find the prime number and the highest power can be easily find out by :

countofpower = [n/a] + [n/a^2] + [n/a^3] +...... or ` while (n)
{
n/ = a;
ans += n
}
Count Of Factors = (ans1 +1)*(ans2 +1)*....(ansk +1)

After calculating this last step is the sum :

SUM = product of all (pow(ak,pk+1)-1)/(ak-1);
ex = 4!
4! = 2^3 * 3^1;
count of factors = (3+1)*(1+1) = 8 (1,2,3,4,6,8,12,24)
sum = ( 1 + 2 + 4 + 8)*(1 + 3) = 60.