Project Euler 5
Posted jerryberry
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Project Euler 5相关的知识,希望对你有一定的参考价值。
Problem 5
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?
Solve:
-
clear
clc
for i = 100:20:1000000000
% if rem(i,11) == 0 && rem(i,12) == 0 && rem(i,13) == 0 && rem(i,14) == 0 && rem(i,15) == 0 &&rem(i,16) == 0 && rem(i,17) == 0 && rem(i,18) == 0 && rem(i,19) == 0 && rem(i,20) == 0
break
end
end
fprintf(‘The smallest evenly divisible number is %.0d\n‘,i) - clear
clc
for i = 100:20:1000000000
for j = 20:-1:1
if mod(i,j) ~= 0
break
end
end
if j == 1
answer = i;
break
end
end
fprintf(‘The smallest evenly divisible number is %.0d\n‘,answer)
以上是关于Project Euler 5的主要内容,如果未能解决你的问题,请参考以下文章