Problem Statement
#include <iostream> #include <ctime> using namespace std; #define sz 362880 long f[10]; long test( long n ){ long sum = 0; while( n ){ sum += f[n % 10]; n /= 10; } return sum; } int main(){ long i,j,k,l,cnt = 0,ans = 0; double st,en; st = clock(); f[0] = 1; f[1] = 1; for( i = 2; i <= 9; i++ ) f[i] = f[i-1] * i; for( i = 3; i <= sz; i++ ){ if( test(i) == i){ ans += i; cnt++; printf("%ld\n",i); } } printf("%ld\n",cnt); printf("ANS : %ld\n",ans); en = clock(); printf("Time required : %lf\n",(en - st)/CLOCKS_PER_SEC); return 0; }
1 comment:
So what would be the pseudocode for this?
Post a Comment