Click here to Skip to main content
15,886,823 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: Specify numbers as product of Primes? Pin
Member 419459326-Jun-08 8:19
Member 419459326-Jun-08 8:19 
GeneralRe: Specify numbers as product of Primes? Pin
Robert.C.Cartaino26-Jun-08 8:47
Robert.C.Cartaino26-Jun-08 8:47 
GeneralRe: Specify numbers as product of Primes? Pin
Ian Uy26-Jun-08 17:51
Ian Uy26-Jun-08 17:51 
GeneralRe: Specify numbers as product of Primes? Pin
cp987629-Jun-08 14:57
cp987629-Jun-08 14:57 
AnswerRe: Specify numbers as product of Primes? Pin
Arash Partow29-Jun-08 0:48
Arash Partow29-Jun-08 0:48 
GeneralRe: Specify numbers as product of Primes? [modified] Pin
cp987629-Jun-08 3:53
cp987629-Jun-08 3:53 
GeneralRe: Specify numbers as product of Primes? Pin
Luc Pattyn29-Jun-08 4:40
sitebuilderLuc Pattyn29-Jun-08 4:40 
GeneralRe: Specify numbers as product of Primes? Pin
cp987629-Jun-08 14:47
cp987629-Jun-08 14:47 
Hi Luc,

True. The most important thing he should do is limit the testing to sqrt(N).

To factorise a number N, you need to test up to sqrt(N), and there are approximately
sqrt(N)/log(sqrt(N)) primes to test. For example, to factorise 1,000,000 you only need to test the 168 primes less than 1000, or 16.8% of the numbers less than 1000.

Using the simple algorithm you test 100% of the numbers less than sqrt(N):
if you eliminate the multiples of 2 you are down to testing about 50%
then eliminating the multiples of 3 drops you to testing 33.3%
then eliminating the multiples of 5 drops you to testing 26.7%
and so on.

the first few are probably worthwhile as you point out, but you then rapidly get in to diminishing returns, and may easily get to the stage where it is not worth the effort to save the time of the line
if(InputCase%i==0)


I don't think multiple threads are worthwhile until you go past 32 bit arithmetic (even the simplest algorithm only has 2^16 tests to do).

Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

modified on Sunday, June 29, 2008 10:10 PM

GeneralRe: Specify numbers as product of Primes? Pin
Arash Partow30-Jun-08 2:54
Arash Partow30-Jun-08 2:54 
GeneralRe: Specify numbers as product of Primes? Pin
cp987630-Jun-08 3:18
cp987630-Jun-08 3:18 
GeneralRe: Specify numbers as product of Primes? Pin
Arash Partow30-Jun-08 4:27
Arash Partow30-Jun-08 4:27 
GeneralRe: Specify numbers as product of Primes? Pin
Arash Partow30-Jun-08 2:17
Arash Partow30-Jun-08 2:17 
Questionlogic of prob function in ms excel Pin
sumit703425-Jun-08 0:40
sumit703425-Jun-08 0:40 
QuestionFactorials Pin
Ian Uy24-Jun-08 8:17
Ian Uy24-Jun-08 8:17 
AnswerRe: Factorials Pin
Tim Craig24-Jun-08 10:29
Tim Craig24-Jun-08 10:29 
GeneralRe: Factorials Pin
Ian Uy25-Jun-08 6:32
Ian Uy25-Jun-08 6:32 
GeneralRe: Factorials Pin
Tim Craig25-Jun-08 8:55
Tim Craig25-Jun-08 8:55 
GeneralRe: Factorials Pin
Luc Pattyn25-Jun-08 11:01
sitebuilderLuc Pattyn25-Jun-08 11:01 
GeneralRe: Factorials Pin
Tim Craig25-Jun-08 21:06
Tim Craig25-Jun-08 21:06 
AnswerRe: Factorials Pin
cp987624-Jun-08 12:33
cp987624-Jun-08 12:33 
AnswerRe: Factorials Pin
Matthew Butler24-Jun-08 12:38
Matthew Butler24-Jun-08 12:38 
GeneralRe: Factorials Pin
cp987624-Jun-08 14:05
cp987624-Jun-08 14:05 
GeneralRe: Factorials Pin
Luc Pattyn24-Jun-08 15:02
sitebuilderLuc Pattyn24-Jun-08 15:02 
GeneralRe: Factorials Pin
cp987624-Jun-08 20:09
cp987624-Jun-08 20:09 
GeneralRe: Factorials Pin
Luc Pattyn24-Jun-08 23:53
sitebuilderLuc Pattyn24-Jun-08 23:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.