To check divisibility of any large number by 999 | function to check divisibility ; Append required 0 s at the beginning . ; add digits in group of three in gSum ; group saves 3 - digit group ; calculate result till 3 digit sum ; Driver Code
function isDivisible999 ( num ) { let n = num . length ; if ( n == 0 && num [ 0 ] == ' ' ) return true ; if ( n % 3 == 1 ) num = " " + num ; if ( n % 3 == 2 ) num = " " + num ; let gSum = 0 ; for ( let i = 0 ; i < n ; i += 3 ) { group = 0 ; group += ( num . charCodeAt ( i ) - 48 ) * 100 ; group += ( num . charCodeAt ( i + 1 ) - 48 ) * 10 ; group += ( num . charCodeAt ( i + 2 ) - 48 ) ; gSum += group ; } if ( gSum > 1000 ) { num = String ( gSum ) ; n = strlen ( num ) ; gSum = isDivisible999 ( num ) ; } return ( gSum == 999 ) ; } let num = " " ; if ( isDivisible999 ( num ) ) document . write ( " " ) ; else document . write ( " " ) ;