Sum of n digit numbers divisible by a given number | Find the Sum of having n digit and divisible by the number ; Compute the first and last term ; First number which is divisible by given number ; Last number which is divisible by given number ; Total divisible number ; Return the total sum ; Driver Code
function totalSumDivisibleByNum ( digit , number ) { let firstnum = Math . pow ( 10 , digit - 1 ) ; let lastnum = Math . pow ( 10 , digit ) ; firstnum = ( firstnum - firstnum % number ) + number ; lastnum = ( lastnum - lastnum % number ) ; let count = ( ( lastnum - firstnum ) / number + 1 ) ; return ( ( lastnum + firstnum ) * count ) / 2 ; } let n = 3 , number = 7 ; document . write ( totalSumDivisibleByNum ( n , number ) ) ;