In the Prime practice problem, there's a thought question that says:
Can you make the prime-finding algorithm more efficient than checking if a number is divisible by every number between 2 and 1 less than itself? Can you think of another way to generate prime numbers?
Here's what I came up with:
bool prime(int number)
{
if (number == 2 || number == 3 || number == 5)
{
return true;
}
else if (number == 1 || number % 2 == 0 || number % 3 == 0 || number % 5 == 0)
{
return false;
}
else
{
return true;
}
}
I'm still pretty new to programming, so I don't really know how to make a piece of code more efficient. What do you think about my solution? Is it more efficient than using a loop?