12,819,421 members (30,158 online)

# Algorithms

 Re: Specify numbers as product of Primes? ChandraRam2-Jul-08 23:49 ChandraRam 2-Jul-08 23:49
 Re: Specify numbers as product of Primes? MarkBrock3-Jul-08 0:06 MarkBrock 3-Jul-08 0:06
 Re: Specify numbers as product of Primes? Member 419459326-Jun-08 9:19 Member 4194593 26-Jun-08 9:19
 Re: Specify numbers as product of Primes? Robert.C.Cartaino26-Jun-08 9:47 Robert.C.Cartaino 26-Jun-08 9:47
 Re: Specify numbers as product of Primes? Ian Uy26-Jun-08 18:51 Ian Uy 26-Jun-08 18:51
 Re: Specify numbers as product of Primes? cp987629-Jun-08 15:57 cp9876 29-Jun-08 15:57
 Re: Specify numbers as product of Primes? Arash Partow29-Jun-08 1:48 Arash Partow 29-Jun-08 1:48
 Re: Specify numbers as product of Primes? [modified] cp987629-Jun-08 4:53 cp9876 29-Jun-08 4:53
  since Arash has completely changed the code in his previous post, this appears somewhat out of context [/edit]I think this is an example of misguided optimization. Whilst Ian Uy's example looks inefficient```int main() { int InputCase; cin >> InputCase; for(int i=2;i<=InputCase;i++) { if(InputCase%i==0) { cout << i; InputCase/=i; i--; } } return 0; }```all he is doing each iteration is testing ```if(InputCase%i==0) ```In order to avoid these "unnecessary" tests, you are testing each n as```if (n % 2 == 0) n++; while(!is_prime(n)) { ++n; } ```The function is_prime(n) will involve much more overhead than the original code, and it doesn't matter that 'i' may not be prime. 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 Saturday, October 18, 2008 11:35 PM
 Re: Specify numbers as product of Primes? Luc Pattyn29-Jun-08 5:40 Luc Pattyn 29-Jun-08 5:40
 Re: Specify numbers as product of Primes? cp987629-Jun-08 15:47 cp9876 29-Jun-08 15:47
 Re: Specify numbers as product of Primes? Arash Partow30-Jun-08 3:54 Arash Partow 30-Jun-08 3:54
 Re: Specify numbers as product of Primes? cp987630-Jun-08 4:18 cp9876 30-Jun-08 4:18
 Re: Specify numbers as product of Primes? Arash Partow30-Jun-08 5:27 Arash Partow 30-Jun-08 5:27
 Re: Specify numbers as product of Primes? Arash Partow30-Jun-08 3:17 Arash Partow 30-Jun-08 3:17
 logic of prob function in ms excel sumit703425-Jun-08 1:40 sumit7034 25-Jun-08 1:40
 Factorials Ian Uy24-Jun-08 9:17 Ian Uy 24-Jun-08 9:17
 Re: Factorials Tim Craig24-Jun-08 11:29 Tim Craig 24-Jun-08 11:29
 Re: Factorials Ian Uy25-Jun-08 7:32 Ian Uy 25-Jun-08 7:32
 Re: Factorials Tim Craig25-Jun-08 9:55 Tim Craig 25-Jun-08 9:55
 Re: Factorials Luc Pattyn25-Jun-08 12:01 Luc Pattyn 25-Jun-08 12:01
 Re: Factorials Tim Craig25-Jun-08 22:06 Tim Craig 25-Jun-08 22:06
 Re: Factorials cp987624-Jun-08 13:33 cp9876 24-Jun-08 13:33
 Re: Factorials Matthew Butler24-Jun-08 13:38 Matthew Butler 24-Jun-08 13:38
 Re: Factorials cp987624-Jun-08 15:05 cp9876 24-Jun-08 15:05
 Re: Factorials Luc Pattyn24-Jun-08 16:02 Luc Pattyn 24-Jun-08 16:02
 Last Visit: 31-Dec-99 19:00     Last Update: 25-Mar-17 6:00 Refresh « Prev1...161162163164165166167168169170 Next »