Find the first natural number whose factorial is divisible by x | Java program for finding the Special Factorial Number ; function for calculating factorial ; function for check Special_Factorial_Number ; call fact function and the Modulo with k and check if condition is TRUE then return i ; driver function ; taking input
public class GFG { static int fact ( int n ) { int num = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { num = num * i ; } return num ; } static int Special_Factorial_Number ( int k ) { for ( int i = 1 ; i <= k ; i ++ ) { if ( fact ( i ) % k == 0 ) { return i ; } } return 0 ; } public static void main ( String [ ] args ) { int k = 16 ; System . out . println ( Special_Factorial_Number ( k ) ) ; } }