Click here to Skip to main content

Algorithms

 
GeneralRe: Specify numbers as product of Primes? PinmemberIan Uy26-Jun-08 18:51 
GeneralRe: Specify numbers as product of Primes? Pinmembercp987629-Jun-08 15:57 
AnswerRe: Specify numbers as product of Primes? PinmemberArash Partow29-Jun-08 1:48 
GeneralRe: Specify numbers as product of Primes? [modified] Pinmembercp987629-Jun-08 4:53 
GeneralRe: Specify numbers as product of Primes? PinmvpLuc Pattyn29-Jun-08 5:40 
GeneralRe: Specify numbers as product of Primes? Pinmembercp987629-Jun-08 15:47 
GeneralRe: Specify numbers as product of Primes? PinmemberArash Partow30-Jun-08 3:54 
GeneralRe: Specify numbers as product of Primes? Pinmembercp987630-Jun-08 4:18 
Arash Partow wrote:
I believe this is not correct, assume you have an x composed from 2p where p is a prime, in this case it is clear that in certain circumstance sqrt(x) can be less than p (eg: 15838 = 7919 * 2, where 7919 > sqrt(15838)), for primal testing the sqrt(n) bound is ok, however its not suitable for the upper bound in this problem.

 
He's studying for the ACM competition - I don't want to spoon feed him! He can limit his testing to sqrt(N) but he has to modify his algorithm slightly for when InputCase is not 1 at the end.
 
In the example you give, he only needs to test until floor(sqrt(15838))=125, he will have only found 2 as a factor and InputCase will be 7919 after the 124 tests. He can then conclude the the remaining value in InputCase is the remaining prime factor. This is much more efficient than testing the remaining 15,703 factors.
 
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."

GeneralRe: Specify numbers as product of Primes? PinmemberArash Partow30-Jun-08 5:27 
GeneralRe: Specify numbers as product of Primes? PinmemberArash Partow30-Jun-08 3:17 
Questionlogic of prob function in ms excel Pinmembersumit703425-Jun-08 1:40 
QuestionFactorials PinmemberIan Uy24-Jun-08 9:17 
AnswerRe: Factorials PinmemberTim Craig24-Jun-08 11:29 
GeneralRe: Factorials PinmemberIan Uy25-Jun-08 7:32 
GeneralRe: Factorials PinmemberTim Craig25-Jun-08 9:55 
GeneralRe: Factorials PinmvpLuc Pattyn25-Jun-08 12:01 
GeneralRe: Factorials PinmemberTim Craig25-Jun-08 22:06 
AnswerRe: Factorials Pinmembercp987624-Jun-08 13:33 
AnswerRe: Factorials PinmemberMatthew Butler24-Jun-08 13:38 
GeneralRe: Factorials Pinmembercp987624-Jun-08 15:05 
GeneralRe: Factorials PinmvpLuc Pattyn24-Jun-08 16:02 
GeneralRe: Factorials Pinmembercp987624-Jun-08 21:09 
GeneralRe: Factorials PinmvpLuc Pattyn25-Jun-08 0:53 
GeneralRe: Factorials Pinmembercp987625-Jun-08 3:27 
GeneralRe: Factorials PinmvpLuc Pattyn25-Jun-08 3:34 

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

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


Advertise | Privacy | Mobile
Web03 | 2.8.150302.1 | Last Updated 2 Mar 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid