-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem5.m
More file actions
27 lines (24 loc) · 726 Bytes
/
problem5.m
File metadata and controls
27 lines (24 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
%%
% 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
%
% What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
%%
clearvars;
% by hand:
result = 1*2*3*2*5*7*2*3*11*13*2*17*19;
% find all prime numbers smaller than 20:
numbers = 2:20;
numbers = numbers(isprime(numbers));
% we insert a prime number as many times into our list, until p^n >20. this
% way, all numbers <=20 can be calculated from our list of primes. this
% list is irreducible the prime factors of our result.
list = 1;
for ii=numbers
k=ii;
while( k<20 )
list = [list ii];
k=k*ii;
end
end
result = prod(list)
% result = 232792560