Sum of n digit numbers divisible by a given number | Returns sum of n digit numbers divisible by ' number ' ; compute the first and last term ; sum of number which having n digit and divisible by number ; Driver code
< ? php function totalSumDivisibleByNum ( $ n , $ number ) { $ firstnum = pow ( 10 , $ n - 1 ) ; $ lastnum = pow ( 10 , $ n ) ; $ sum = 0 ; for ( $ i = $ firstnum ; $ i < $ lastnum ; $ i ++ ) if ( $ i % $ number == 0 ) $ sum += $ i ; return $ sum ; } $ n = 3 ; $ num = 7 ; echo totalSumDivisibleByNum ( $ n , $ num ) , " " ; ? >