You are viewing a single comment's thread. Return to all comments →
using namespace std;
unsigned long long factorial(long num) { unsigned long long mult = 1; while (num > 1) { mult *= num; num--; } return mult; }
int main() { long n; cin >> n; for (long i = 0; i < n; i++) { long current; cin >> current;
unsigned long long fact = factorial(current); long sum_of_digits = 0; while (fact > 0) { sum_of_digits += fact % 10; fact /= 10; } cout << sum_of_digits << endl; } return 0;
}
Can anyone explain what's wrong in my code? Only 2/4 test cases have successfully ran, and all remaining test cases were unsuccessful.
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #20: Factorial digit sum
You are viewing a single comment's thread. Return to all comments →
include
include
include
include
include
using namespace std;
unsigned long long factorial(long num) { unsigned long long mult = 1; while (num > 1) { mult *= num; num--; } return mult; }
int main() { long n; cin >> n; for (long i = 0; i < n; i++) { long current; cin >> current;
}
Can anyone explain what's wrong in my code? Only 2/4 test cases have successfully ran, and all remaining test cases were unsuccessful.