/    Sign up×
Community /Pin to ProfileBookmark

quickest way to prove primality

Hi guys:

Trying to write a function to prove is a number is a prime.
Whilst i have it working i don’t think its the most efficient way.

I basically find all the factors of the number and then count how many factors it has, if its 2 its prime. problem there is if i input 123456789, it has to loop through every number between 0 and 123456789.

Any better suggestions?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyMar 23.2007 — when it reaches three break the loop.
Copy linkTweet thisAlerts:
@Sid3335authorMar 23.2007 — yep already does that, i was just wondering if there is a better mathematical way of doing it.
Copy linkTweet thisAlerts:
@bathurst_guyMar 23.2007 — better mathematical way - yes . easy - i dont think so.

See if this [url=http://en.wikipedia.org/wiki/Prime_numbers]wikipedia article[/url] helps.
×

Success!

Help @Sid3335 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...