Check whether a large number is divisible by 53 or not | Java program to check whether a number is divisible by 53 or not ; Function to check if the number is divisible by 53 or not ; Driver Code
import java . util . * ; class GFG { static boolean isDivisible ( char [ ] s ) { while ( s . length > 4 ) { int l = s . length - 1 ; int x = ( s [ l ] - '0' ) * 37 ; s = reverse ( s ) ; s = Arrays . copyOfRange ( s , 1 , s . length ) ; int i = 0 , carry = 0 ; while ( x > 0 ) { int d = ( s [ i ] - '0' ) - ( x % 10 ) - carry ; if ( d < 0 ) { d += 10 ; carry = 1 ; } else carry = 0 ; s [ i ] = ( char ) ( d + '0' ) ; x /= 10 ; i ++ ; } while ( carry > 0 && i < l ) { int d = ( s [ i ] - '0' ) - carry ; if ( d < 0 ) { d += 10 ; carry = 1 ; } else carry = 0 ; s [ i ] = ( char ) ( d + '0' ) ; i ++ ; } s = reverse ( s ) ; } int num = 0 ; for ( int i = 0 ; i < s . length ; i ++ ) { num = num * 10 + ( s [ i ] - '0' ) ; } if ( num % 53 == 0 ) return true ; else return false ; } static char [ ] reverse ( char [ ] a ) { int l , r = a . length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { char temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return a ; } public static void main ( String [ ] args ) { String N = "18432462191076" ; if ( isDivisible ( N . toCharArray ( ) ) ) System . out . print ( " Yes " + "NEW_LINE"); else System . out . print ( " No " + "NEW_LINE"); } }