Sourabh Singh
Last Activity: 10 Years ago
Hii
look up the solution to get tyhe approach how to proceed
Sum of all numbers 1 to 100:
S = n[2a1 + (n - 1)d]/2
= 100[2(1) + (100 - 1)]/2
= 100(101)/2
= 5050
Sum of all numbers 3 to 99, multiples of 3:
S = n[2a1 + (n - 1)d]/2
= 33[2(3) + (33 - 1)3]/2
= 33(6 + 96)/2
= 1683
Sum of all numbers 5 to 100, multiples of 5:
S = n[2a1 + (n - 1)d]/2
= 20[2(5) + (20 - 1)5]/2
= 20(10 + 95)/2
= 1050
Sum of all numbers 15 to 90, multiples of 15:
S = n[2a1 + (n - 1)d]/2
= 6[2(15) + (6 - 1)15]/2
= 6(30 + 75)/2
= 315
Sum of integers from 1 to 100 which are not divisible by 3 and 5:
S = sum(1-100) - sum(3-99) - sum(5-100) + sum(15-90)
= 5050 - 1683 - 1050 + 315
= 2632
We have to add in the sum(15-90) because in removing sum(3-99) and sum(5-100), we're taking out multiples of 15 twice. Adding sum(15-90) ensures that we only take out 15 once, 30 once, etc.