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:

  1. 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)

  2. 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)
上一篇:LINIUX 查询命令的 区别 chich whereis locate fing


下一篇:Leetcode 1029. Binary Prefix Divisible By 5