# Write a function called smallest_multiple

10 views (last 30 days)

Show older comments

##### 0 Comments

### Answers (2)

Image Analyst
on 4 Mar 2018

Here is a hint:

function results = smallest_multiple(n)

% Your code goes here

Next step, read this:

##### 0 Comments

Srishti Saha
on 13 May 2018

Here is a solution that worked for me:

%%alternative solution to smallest multiple

function r = smallest_multiple(k)

r = uint64(1);

for n = 1:k

r = r * (n / gcd(r,n));

end

if r == intmax('uint64')

r = uint64(0);

end

end

##### 4 Comments

Ranil Fernando
on 3 Jun 2018

Edited: Ranil Fernando
on 3 Jun 2018

My code is working outside the grader for n=13 without taking a longer time. But within the grader it fails for even 2. Someone please give me a hand here.

function multiN = smallest_multiple(n)

mod2N = 0;

multiN = uint64(n);

while all(mod2N) == 0

multiN = multiN + 1;

mod2N = zeros(1,n);

for ii=1:n

if mod(multiN,ii) == 0

mod2N(ii) = 1;

elseif multiN == intmax('uint64')

multiN = uint64(0);

end

end

end

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!