Divide number into two parts divisible by given numbers | method prints divisible parts if possible , otherwise prints ' Not ▁ possible ' ; creating arrays to store reminder ; looping over all suffix and storing reminder with f ; getting suffix reminder from previous suffix reminder ; looping over all prefix and storing reminder with s ; getting prefix reminder from next prefix reminder ; updating base value ; now looping over all reminders to check partition condition ; if both reminders are 0 and digit itself is not 0 , then print result and return ; if we reach here , then string can ' be partitioned  under constraints ; Driver code
< ? php function printTwoDivisibleParts ( $ num , $ f , $ s ) { $ N = strlen ( $ num ) ; $ prefixReminder = array_fill ( 0 , $ N + 1 , 0 ) ; $ suffixReminder = array_fill ( 0 , $ N + 1 , 0 ) ; for ( $ i = 1 ; $ i < $ N ; $ i ++ ) $ suffixReminder [ $ i ] = ( $ suffixReminder [ $ i - 1 ] * 10 + ( ord ( $ num [ $ i - 1 ] ) - 48 ) ) % $ f ; $ base = 1 ; for ( $ i = $ N - 1 ; $ i >= 0 ; $ i -- ) { $ prefixReminder [ $ i ] = ( $ prefixReminder [ $ i + 1 ] + ( ord ( $ num [ $ i ] ) - 48 ) * $ base ) % $ s ; $ base = ( $ base * 10 ) % $ s ; } for ( $ i = 0 ; $ i < $ N ; $ i ++ ) { if ( $ prefixReminder [ $ i ] == 0 && $ suffixReminder [ $ i ] == 0 && $ num [ $ i ] != '0' ) { echo substr ( $ num , 0 , $ i ) . " ▁ " . substr ( $ num , $ i ) . " STRNEWLINE " ; return ; } } echo " Not ▁ Possible STRNEWLINE " ; } $ num = "246904096" ; $ f = 12345 ; $ s = 1024 ; printTwoDivisibleParts ( $ num , $ f , $ s ) ; ? >