Program for quotient and remainder of big number | Java program to find quotient and remainder when a number is divided by large number represented as String . ; 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
import java . util . Vector ; class GFG { static void modBigNumber ( String num , long m ) { Vector < Integer > vec = new Vector < > ( ) ; long mod = 0 ; for ( int i = 0 ; i < num . length ( ) ; i ++ ) { int digit = num . charAt ( i ) - '0' ; mod = mod * 10 + digit ; int quo = ( int ) ( mod / m ) ; vec . add ( vec . size ( ) , quo ) ; mod = mod % m ; } System . out . print ( " Remainder : " ▁ + ▁ mod ▁ + ▁ " "); System . out . print ( " Quotient ▁ : ▁ " ) ; boolean zeroflag = false ; for ( int i = 0 ; i < vec . size ( ) ; i ++ ) { if ( vec . get ( i ) == 0 && zeroflag == false ) { continue ; } zeroflag = true ; System . out . print ( vec . get ( i ) ) ; } return ; } public static void main ( String [ ] args ) { String num = "14598499948265358486" ; long m = 487 ; modBigNumber ( num , m ) ; } }