/* Find the sum of all numbers which are equal to the sum of the factorial of their digits. */#include <stdio.h>intsolve(){intf[10];inti,limit,sum;f[0]=1;for(i=1;i<10;i++)f[i]=f[i-1]*i;limit=7*f[9];sum=0;for(i=3;i<=limit;i++){ints=0;intj=i;while(j>0){s+=f[j%10];j/=10;}if(i==s)sum+=i;}returnsum;}intmain(){printf("%d\n",solve());return0;}
1234567891011121314151617181920
# Find the sum of all numbers which are equal to the sum of the factorial of# their digits.importmathdefsolve():f=[math.factorial(i)foriinrange(10)]limit=7*f[9]ret=[]foriinrange(3,limit+1):s=0j=iwhilej>0:s+=f[j%10]j/=10ifi==s:ret.append(i)returnretprintsum(solve())