How to resolve the algorithm Sum multiples of 3 and 5 step by step in the Maxima programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sum multiples of 3 and 5 step by step in the Maxima programming language
Table of Contents
Problem Statement
The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sum multiples of 3 and 5 step by step in the Maxima programming language
Source code in the maxima programming language
sumi(n, inc):= block(
[kmax],
/* below n means [1 .. n-1] */
kmax: quotient(n-1, inc),
return(
''(ev(sum(inc*k, k, 1, kmax), simpsum))
)
);
sum35(n):= sumi(n, 3) + sumi(n, 5) - sumi(n, 15);
sum35(1000);
sum35(10^20);
You may also check:How to resolve the algorithm Function frequency step by step in the REXX programming language
You may also check:How to resolve the algorithm Sum multiples of 3 and 5 step by step in the Oforth programming language
You may also check:How to resolve the algorithm Read entire file step by step in the REALbasic programming language
You may also check:How to resolve the algorithm Ethiopian multiplication step by step in the 11l programming language
You may also check:How to resolve the algorithm Averages/Pythagorean means step by step in the Icon and Unicon programming language