Saint | Java program for above approach ; Function to check if a number is a Saint - Exupery number ; Considering triplets in sorted order . The value of first element in sorted triplet can be at - most n / 3. ; The value of second element must be less than equal to n / 2 ; Driver Code ; Given Number N ; Function Call
class GFG { static boolean isSaintExuperyNum ( int n ) { for ( int i = 1 ; i <= n / 3 ; i ++ ) { for ( int j = i + 1 ; j <= n / 2 ; j ++ ) { int k = n / i / j ; if ( i * i + j * j == k * k ) { if ( i * j * k == n ) return true ; } } } return false ; } public static void main ( String [ ] args ) { int N = 60 ; if ( isSaintExuperyNum ( N ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }