Find the missing digit in given product of large positive integers | Java program for the above approach ; Function to find the replaced digit in the product of a * b ; Keeps track of the sign of the current digit ; Stores the value of a % 11 ; Find the value of a mod 11 for large value of a as per the derived formula ; Stores the value of b % 11 ; Find the value of b mod 11 for large value of a as per the derived formula ; Stores the value of c % 11 ; Keeps track of the sign of x ; If the current digit is the missing digit , then keep the track of its sign ; Find the value of x using the derived equation ; Check if x has a negative sign ; Return positive equivaluent of x mod 11 ; Driver Code
class GFG { public static int findMissingDigit ( String a , String b , String c ) { int w = 1 ; int a_mod_11 = 0 ; for ( int i = a . length ( ) - 1 ; i >= 0 ; i -- ) { a_mod_11 = ( a_mod_11 + w * ( a . charAt ( i ) - '0' ) ) % 11 ; w = w * - 1 ; } int b_mod_11 = 0 ; w = 1 ; for ( int i = b . length ( ) - 1 ; i >= 0 ; i -- ) { b_mod_11 = ( b_mod_11 + w * ( b . charAt ( i ) - '0' ) ) % 11 ; w = w * - 1 ; } int c_mod_11 = 0 ; boolean xSignIsPositive = true ; w = 1 ; for ( int i = c . length ( ) - 1 ; i >= 0 ; i -- ) { if ( c . charAt ( i ) == ' x ' ) { xSignIsPositive = ( w == 1 ) ; } else { c_mod_11 = ( c_mod_11 + w * ( c . charAt ( i ) - '0' ) ) % 11 ; } w = w * - 1 ; } int x = ( ( a_mod_11 * b_mod_11 ) - c_mod_11 ) % 11 ; if ( ! xSignIsPositive ) { x = - x ; } return ( x % 11 + 11 ) % 11 ; } public static void main ( String args [ ] ) { String A = "123456789" ; String B = "987654321" ; String C = "12193263111x635269" ; System . out . println ( findMissingDigit ( A , B , C ) ) ; } }