Smallest integer greater than n such that it consists of digit m exactly k times | Function that returns true if n contains digit m exactly k times ; Function to return the smallest integer > n with digit m occurring exactly k times ; Driver code
< ? php function digitWell ( $ n , $ m , $ k ) { $ cnt = 0 ; while ( $ n > 0 ) { if ( $ n % 10 == $ m ) ++ $ cnt ; $ n = floor ( $ n / 10 ) ; } return $ cnt == $ k ; } function findInt ( $ n , $ m , $ k ) { $ i = $ n + 1 ; while ( true ) { if ( digitWell ( $ i , $ m , $ k ) ) return $ i ; $ i ++ ; } } $ n = 111 ; $ m = 2 ; $ k = 2 ; echo findInt ( $ n , $ m , $ k ) ; ? >