Find the Smallest number that divides X ^ X | Java implementation of above approach ; Function to find the required smallest number ; Finding smallest number that divides n ; i divides n and return this value immediately ; If n is a prime number then answer should be n , as we can 't take 1 as our answer. ; Driver Code
class GFG { static int SmallestDiv ( int n ) { for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { return i ; } } return n ; } public static void main ( String [ ] args ) { int X = 385 ; int ans = SmallestDiv ( X ) ; System . out . print ( ans + "NEW_LINE"); } }