Sum of multiples of a number up to N | Function for calculating sum of multiples of a upto N ; Number of multiples ; sum of first m natural numbers ; sum of multiples ; Driver code
< ? php function calculate_sum ( $ a , $ N ) { $ m = $ N / $ a ; $ sum = $ m * ( $ m + 1 ) / 2 ; $ ans = $ a * $ sum ; return $ ans ; } $ a = 7 ; $ N = 49 ; echo " Sum ▁ of ▁ multiples ▁ of ▁ " . $ a , " ▁ up ▁ to ▁ " . $ N . " ▁ = ▁ " . calculate_sum ( $ a , $ N ) ; ? >