Can you make this more efficeint?
Written in C++ and this check's if a number is prime. It's really simple, and it returns '0' if it's prime or '1' if it's not prime.
Wondering if anyone can make this more efficient? PHP Code:
|
Re: Can you make this more efficeint?
depends...
If you know the upper limit and you want to use it very often then you can use this: PHP Code:
|
Re: Can you make this more efficeint?
|
Re: Can you make this more efficeint?
Now lets find the pattern to prime numbers. lol.
|
Re: Can you make this more efficeint?
The pattern is... You can't divide the number of anything but itself and 1 to get another whole number.
:gasp: 5/1.... nope 5/2.. nope 5/3.... nope 5/4... nope... 5 IS PRIME! I r teh smartiest. |
Re: Can you make this more efficeint?
/me bows down to TheNewt and ties his shoelaces around his feet
|
Re: Can you make this more efficeint?
EDIT: Crap.
|
Re: Can you make this more efficeint?
You can still optimize it further with a simple check.
|
Re: Can you make this more efficeint?
Wow, 2 min and 40 seconds? Mine did 1 million in 14 seconds.
|
Re: Can you make this more efficeint?
modulo is a powerful mathematical tool ;)
|
| All times are GMT -4. The time now is 02:23. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.