Find the sum of all integers between 1 and 9999 that are divisible by 5 but not by 6 nor 7.
Any help is greatly appreciated!
Printable View
Find the sum of all integers between 1 and 9999 that are divisible by 5 but not by 6 nor 7.
Any help is greatly appreciated!
Answer is 7137125
Matlab code:
a = 0;
for i = 1:9999
if mod(i,5) == 0 && mod(i,6) ~= 0 && mod(i,7) ~= 0
a = a + i;
end
end
disp(a);
Is there a way of not using a calculater to work this out, in a logic way, by not also writing all the numbers out.
Is there a way of not using a calculater to work this out, in a logic way, by not also writing all the numbers out.Quote:
Originally Posted by paultwang
Reply With Quote
> 9999/5.;
1999.8
> 9999/30.;
333.3000000
> 9999/35.;
285.6857143
> 9999/210.;
47.61428571
> 1999*(1+1999)/2*5;
9995000
> 333*334/2*30;
1668330
> 285*286/2*35;
1426425
> 47*48/2*210;
236880
> 9995000-1668330-1426425+236880;
7137125
Thanks buggler@Undernet for the help on this method.
Thanks for the help