The sum of integers from 1 to 100 inclusive which are divisible by 2 or 5 (or both) is
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
2(1+2+3+4+...+50) = 2550
5(1+2+3+...+20) = 1050
(multiples of 2 & 5) 10(1+2+...+10) = 550
Apply Inclusion-Exclusion Principle, i.e., 2550+1050-550=3050.
Thus, the answer is 3050.
void main() {
int i,j,k,sum;
int a[100];
for(i=2,k=0;i<=100;i++) {
if(i % 2== 0 || i%5==0) {
a[k]=i;
k++;
}
}
for(j=sum=0;j<k;j++)
sum+=a[j];
printf("\n\n%d,",sum);
}
waow :)
I know it's fun to write programs to do stuff but this really isn't a Computer Science problem!
S = 2 + 4 + 5 + 6 + 8 + 10 + 12 + 14 + 15 + 16 + .........+100 = (2 + 4 + 6 + 8 + 10 + ..... + 100) + (5 + 15 + 25 + ..... + 95) = 2x(1+2+3+4+.....+50) + 5(1+3+5+......+19) = (2x½ x 50 x 51) + {5x½x(1+19)x10} = 2550 + 500 = 3050
I did something similar. I first found the pattern in the first 10 numbers set (2,4,5,6,8,10). We already know that it is going to follow as a series (i.e. 12,14,15,16,18,20 and continue 22,24,25,26,28,30 and so on). Now 2+4+5+6+8+10 is 35. For every 10 sets until 100, there is a jump of 60 (since there are 6 numbers in each set). So for the first set jump is 0 (total sum for this set: 0+35=35), second jump: 60 (total sum for this set: 60+35), third jump: 120 (total sum for this set: 120+35) and so on. now once the pattern is got it is easy.
the final answer X = 2 + 4 + 5 + 6 + 8 + 10 + 12 + 14 + 15 + 16 + 18 + 20 + 22 +....
from the above set based jump, X = 35*10 (for the 10 sets) + 60 (0+1+2+3...9) again jump for each of the 10 sets.
hence X = 350 + 60 ((9+10)/2) == 3050!
sum of integers from 1 to 100 that are divisible by 2 =n(n+1) =50*51 =2550 sum of integers from 1 to 100 that are divisible by 5 but not divisible by 2. are 5,15,.25,----------95 = 10/2 (5+95) = 500 The sum of integers from 1 to 100 that are divisible by 2 or 5 is=2550+500=3050 Ans
Your solution answers the question for "2 or 5" instead of "2 and 5".
I have since edited the problem to be properly phrased. Those who previously answered 450 or 550 have also been marked correct.
S n = 1 0 3 n 2 + 5 n
1 2 3 4 5 6 7 |
|
JavaScript code ( can run in browser console )
First sum digits divisible by 2 which is 2550. Then sum the digits divisible by 5 which is 1050. now subtract digits common to both which are digits divisible by 10 which is 550. therefore answer is 2550+1050-550=3050.
sum to 50 even numbers(since there are only 50 even numbers from 1 to 100) is 2550 [ using S_50 = 50/2 (2x2 + 49x2) ]
sum of numbers which are not divisible by 5 but divisible by 2 is
2550 - 10 (1+2+3+5+6+7+8+9+10) = 2000
the number of numbers divisible by 5 from 1 to 100 is 20.
The sum of such numbers is (using the same formula above used) is 1050. Hence
the sum of numbers that are divisible by 2 and 5 from 1 to 100 is 2000+1050 = 3050
Problem Loading...
Note Loading...
Set Loading...
The '2 multiple' there are 50 terms, because 2 1 0 0 = 5 0 . Then a is the first term and b is the difference between each term.
S 5 0 = 2 n ( 2 a + ( n − 1 ) b )
S 5 0 = 2 5 0 ( 2 × 2 + ( 5 0 − 1 ) 2 )
S 5 0 = 5 0 ( 2 + 4 9
S 5 0 = 2 5 5 0
Then the term that can divided by 5 but can't be divided by 2 because the terms have been included in the '2 multiple' terms.
5 + 1 5 + 2 5 + 3 5 + 4 5 + 5 5 + 6 5 + 7 5 + 8 5 + 9 5 = 5 0 0
So, 2 5 5 0 + 5 0 0 = 3 0 5 0