Count factorial numbers in a given range - GeeksforGeeks
A number F is a factorial number if there exists some integer I >= 0 such that F = I! (that is, F is factorial of I). Examples of factorial numbers are 1, 2, 6, 24, 120, ….
Write a program that takes as input two long integers 'low' and 'high' where 0 < low < high and finds count of factorial numbers in the closed interval [low, high].
Read full article from Count factorial numbers in a given range - GeeksforGeeks
A number F is a factorial number if there exists some integer I >= 0 such that F = I! (that is, F is factorial of I). Examples of factorial numbers are 1, 2, 6, 24, 120, ….
Write a program that takes as input two long integers 'low' and 'high' where 0 < low < high and finds count of factorial numbers in the closed interval [low, high].
int countFact(int low, int high){ // Find the first factorial number 'fact' greater than or // equal to 'low' int fact = 1, x = 1; while (fact < low) { fact = fact*x; x++; } // Count factorial numbers in range [low, high] int res = 0; while (fact <= high) { res++; fact = fact*x; x++; } // Return the count return res;}