I am trying to solve Problem 5 in Project Euler website. There is a very bad looking way to code it with too many nested loops. I found a solution online but can anyone please explain the way and approach to do it. I am getting confused by the code that I found.
#include <iostream>
int findProduct( int );
int findProduct(int maxFactor )
{
for ( int n = maxFactor; ; n += maxFactor )
{
for ( int i = 2; i <= maxFactor; i++ )
{
if ( n % i > 0 ) break;
elseif ( i == maxFactor ) return n;
}
}
}
int main()
{
std::cout<<findProduct(20);
return 0;
}
Those problems are not to be "solved" by looking up another persons solution.
They are meant to test your own programming/problem solving skills.
Solve it yourself or choose an easier problem.
Okay.like I said I did that but my solution had a lot of nested loops. and i could not figure it out so tried looking online. I wanted to get the explanantion. Can you provide one?