Know if the number is Prime Or Not Most Optimized Way.
we know by dividing till root N but that's not the best approach.
We can move even further beyond by this technique to increase its efficiency by 3 times.
first we put checks of divisible by 2 and 3
and if not then further go on iterating by increasing the iterator by 6. Why? bcz 2 and 3 would cover up for all the numbers in between.
and another condition inside checking for number divided by iterator+2 for cases like 7,13, etc
Code :
No comments:
Post a Comment