TheAlgorithms / MATLAB-Octave

This repository contains algorithms written in MATLAB/Octave. Developing algorithms in the MATLAB environment empowers you to explore and refine ideas, and enables you test and verify your algorithm.
MIT License
369 stars 175 forks source link

Fix Project Euler problem 3 #86

Closed MaximSmolskiy closed 2 years ago

MaximSmolskiy commented 3 years ago

Current implementation doesn't work due to idivide function - arguments shoud have integer types (not double). After replacing it by number /= divisor implementation works impossible long.

To speed up the program - we should decrease number after divisions by divisors and therefore upper bound sqrt(number) in loop for divisors will decrease quite fast (for loop should be replaced with while to enable upper bound decrease).

And function isPrime is redundant here, because all added divisors will be prime. So, final implementation turned out to be very similar to link