Sunday, 4 June 2023

Prime Optimized

 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

Count of digits in factorial

 To count the digits in a factorial we must seek some optimization as you might also understand that getting all the product and storing the...