Find the Smallest number that divides X ^ X | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int SmallestDiv ( int n ) { for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { return i ; } } return n ; } int main ( ) { int X = 385 ; int ans = SmallestDiv ( X ) ; cout << ans << " STRNEWLINE " ; return 0 ; }