Program for quotient and remainder of big number | Function to calculate the modulus ; Store the modulus of big number ; Do step by step division ; Update modulo by concatenating current digit . ; Update quotient ; Update mod for next iteration . ; Flag used to remove starting zeros ; Driver Code
< ? php function modBigNumber ( $ num , $ m ) { $ vec ; $ x = 0 ; $ mod = 0 ; for ( $ i = 0 ; $ i < strlen ( $ num ) ; $ i ++ ) { $ digit = $ num [ $ i ] - '0' ; $ mod = $ mod * 10 + $ digit ; $ quo = ( int ) ( $ mod / $ m ) ; $ vec [ $ x ++ ] = $ quo ; $ mod = $ mod % $ m ; } echo " Remainder ▁ : ▁ " . $ mod . " STRNEWLINE " ; echo " Quotient ▁ : ▁ " ; $ zeroflag = 0 ; for ( $ i = 0 ; $ i < $ x ; $ i ++ ) { if ( $ vec [ $ i ] == 0 && $ zeroflag == 0 ) continue ; $ zeroflag = 1 ; echo $ vec [ $ i ] ; } return ; } $ num = "14598499948265358486" ; $ m = 487 ; modBigNumber ( $ num , $ m ) ; ? >