N 'th Smart Number | Limit on result ; Function to calculate n 'th smart number  ; Initialize all numbers as not prime ; iterate to mark all primes and smart number ; Traverse all numbers till maximum limit ; ' i ' is maked as prime number because it is not multiple of any other prime ; mark all multiples of ' i ' as non prime ; If i is the third prime factor of j then add it to result as it has at least three prime factors . ; Sort all smart numbers ; return n 'th smart number  ; Driver program to run the case
< ? php $ MAX = 3000 ; function smartNumber ( $ n ) { global $ MAX ; $ primes = array_fill ( 0 , $ MAX , 0 ) ; $ result = array ( ) ; for ( $ i = 2 ; $ i < $ MAX ; $ i ++ ) { if ( $ primes [ $ i ] == 0 ) { $ primes [ $ i ] = 1 ; for ( $ j = $ i * 2 ; $ j < $ MAX ; $ j = $ j + $ i ) { $ primes [ $ j ] -= 1 ; if ( ( $ primes [ $ j ] + 3 ) == 0 ) array_push ( $ result , $ j ) ; } } } sort ( $ result ) ; return $ result [ $ n - 1 ] ; } $ n = 50 ; echo smartNumber ( $ n ) ; ? >