Trimorphic Number | Functions to find nth Trimorphic number ; Comparing the digits ; Return false , if any digit of num doesn ' t ▁ match ▁ with ▁ ▁ its ▁ cube ' s digits from last ; Reduce num and cube ; Check in max int size ; check number is Trimorphic or not ; if counter is equal to the n then return nth number ; Driver code
< ? php function checkTrimorphic ( $ num ) { $ cube = $ num * $ num * $ num ; while ( $ num > 0 ) { if ( $ num % 10 != $ cube % 10 ) return false ; $ num = ( int ) ( $ num / 10 ) ; $ cube = ( int ) ( $ cube / 10 ) ; } return true ; } function nthTrimorphic ( $ n ) { $ count = 0 ; for ( $ i = 0 ; $ i < PHP_INT_MAX ; $ i ++ ) { if ( checkTrimorphic ( $ i ) ) $ count ++ ; if ( $ count == $ n ) return $ i ; } } $ n = 9 ; echo nthTrimorphic ( $ n ) ; ? >