Click here to Skip to main content
13,149,756 members (78,970 online)

Algorithms

 
GeneralRe: Specify numbers as product of Primes? Pin
Paul Conrad28-Jun-08 6:11
memberPaul Conrad28-Jun-08 6:11 
GeneralRe: Specify numbers as product of Primes? Pin
Ravi Bhavnani8-Aug-08 7:16
memberRavi Bhavnani8-Aug-08 7:16 
GeneralRe: Specify numbers as product of Primes? Pin
cp987628-Jun-08 20:27
membercp987628-Jun-08 20:27 
GeneralRe: Specify numbers as product of Primes? Pin
Luc Pattyn29-Jun-08 2:42
mvpLuc Pattyn29-Jun-08 2:42 
GeneralRe: Specify numbers as product of Primes? Pin
MarkBrock27-Jun-08 18:46
memberMarkBrock27-Jun-08 18:46 
GeneralRe: Specify numbers as product of Primes? Pin
Paul Conrad28-Jun-08 5:42
memberPaul Conrad28-Jun-08 5:42 
GeneralRe: Specify numbers as product of Primes? Pin
ChandraRam2-Jul-08 22:49
memberChandraRam2-Jul-08 22:49 
GeneralRe: Specify numbers as product of Primes? Pin
MarkBrock2-Jul-08 23:06
memberMarkBrock2-Jul-08 23:06 
AnswerRe: Specify numbers as product of Primes? Pin
Member 419459326-Jun-08 8:19
memberMember 419459326-Jun-08 8:19 
GeneralRe: Specify numbers as product of Primes? Pin
Robert.C.Cartaino26-Jun-08 8:47
memberRobert.C.Cartaino26-Jun-08 8:47 
GeneralRe: Specify numbers as product of Primes? Pin
Ian Uy26-Jun-08 17:51
memberIan Uy26-Jun-08 17:51 
GeneralRe: Specify numbers as product of Primes? Pin
cp987629-Jun-08 14:57
membercp987629-Jun-08 14:57 
AnswerRe: Specify numbers as product of Primes? Pin
Arash Partow29-Jun-08 0:48
memberArash Partow29-Jun-08 0:48 
GeneralRe: Specify numbers as product of Primes? [modified] Pin
cp987629-Jun-08 3:53
membercp987629-Jun-08 3:53 
[edit] 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

GeneralRe: Specify numbers as product of Primes? Pin
Luc Pattyn29-Jun-08 4:40
mvpLuc Pattyn29-Jun-08 4:40 
GeneralRe: Specify numbers as product of Primes? Pin
cp987629-Jun-08 14:47
membercp987629-Jun-08 14:47 
GeneralRe: Specify numbers as product of Primes? Pin
Arash Partow30-Jun-08 2:54
memberArash Partow30-Jun-08 2:54 
GeneralRe: Specify numbers as product of Primes? Pin
cp987630-Jun-08 3:18
membercp987630-Jun-08 3:18 
GeneralRe: Specify numbers as product of Primes? Pin
Arash Partow30-Jun-08 4:27
memberArash Partow30-Jun-08 4:27 
GeneralRe: Specify numbers as product of Primes? Pin
Arash Partow30-Jun-08 2:17
memberArash Partow30-Jun-08 2:17 
QuestionPolyline offset algorithm Pin
beko16-Jun-08 21:59
memberbeko16-Jun-08 21:59 
AnswerRe: Polyline offset algorithm Pin
Alan Balkany17-Jun-08 4:07
memberAlan Balkany17-Jun-08 4:07 
GeneralRe: Polyline offset algorithm Pin
beko17-Jun-08 4:43
memberbeko17-Jun-08 4:43 
QuestionRe: Polyline offset algorithm Pin
CPallini17-Jun-08 7:03
mvp CPallini17-Jun-08 7:03 
AnswerRe: Polyline offset algorithm Pin
beko17-Jun-08 8:26
memberbeko17-Jun-08 8:26 
GeneralRe: Polyline offset algorithm Pin
cp987617-Jun-08 12:10
membercp987617-Jun-08 12:10 
AnswerRe: Polyline offset algorithm Pin
Arash Partow18-Jun-08 1:22
memberArash Partow18-Jun-08 1:22 
GeneralRe: Polyline offset algorithm Pin
beko18-Jun-08 19:55
memberbeko18-Jun-08 19:55 
Questionneed similar to Excel's "Goal Seek" in C/C++ Pin
KimN6-May-08 9:04
memberKimN6-May-08 9:04 
AnswerRe: need similar to Excel's "Goal Seek" in C/C++ Pin
73Zeppelin6-May-08 9:17
member 73Zeppelin6-May-08 9:17 
GeneralRe: need similar to Excel's "Goal Seek" in C/C++ Pin
KimN6-May-08 10:06
memberKimN6-May-08 10:06 
GeneralRe: need similar to Excel's "Goal Seek" in C/C++ Pin
73Zeppelin6-May-08 10:29
member 73Zeppelin6-May-08 10:29 
AnswerRe: need similar to Excel's "Goal Seek" in C/C++ Pin
cp98766-May-08 15:57
membercp98766-May-08 15:57 
GeneralRe: need similar to Excel's "Goal Seek" in C/C++ Pin
73Zeppelin6-May-08 19:19
member 73Zeppelin6-May-08 19:19 
Questionhow to convert a string to a mathematical function Pin
nta_388626-Sep-07 2:55
membernta_388626-Sep-07 2:55 
AnswerRe: how to convert a string to a mathematical function Pin
DavidCrow26-Sep-07 4:48
mvpDavidCrow26-Sep-07 4:48 
AnswerRe: how to convert a string to a mathematical function Pin
dan neely26-Sep-07 5:25
memberdan neely26-Sep-07 5:25 
GeneralRe: how to convert a string to a mathematical function Pin
El Corazon26-Sep-07 9:45
memberEl Corazon26-Sep-07 9:45 
AnswerRe: how to convert a string to a mathematical function Pin
Russell'27-Sep-07 0:35
memberRussell'27-Sep-07 0:35 
AnswerRe: how to convert a string to a mathematical function Pin
Urs Enzler27-Sep-07 1:16
memberUrs Enzler27-Sep-07 1:16 
AnswerRe: how to convert a string to a mathematical function Pin
Luc Pattyn27-Sep-07 3:29
memberLuc Pattyn27-Sep-07 3:29 
AnswerRe: how to convert a string to a mathematical function Pin
PICguy9-Oct-07 20:57
memberPICguy9-Oct-07 20:57 
GeneralNumerical Recipes in C# Pin
Bassam Abdul-Baki31-Oct-06 5:18
memberBassam Abdul-Baki31-Oct-06 5:18 
GeneralRe: Numerical Recipes in C# Pin
djlove31-Oct-06 22:42
memberdjlove31-Oct-06 22:42 
GeneralMessage Closed Pin
9-Mar-16 21:32
memberMember 123800239-Mar-16 21:32 
GeneralRe: Numerical Recipes in C# Pin
Just me at will_george...something8-Nov-06 3:09
memberJust me at will_george...something8-Nov-06 3:09 
GeneralMessage Closed Pin
9-Mar-16 21:32
memberMember 123800239-Mar-16 21:32 
GeneralMessage Closed Pin
9-Mar-16 21:32
memberMember 123800239-Mar-16 21:32 
Generalfdfdsf Pin
Gul zeb13-Sep-06 21:43
memberGul zeb13-Sep-06 21:43 
GeneralRe: fdfdsf Pin
Ed.Poore14-Sep-06 1:04
memberEd.Poore14-Sep-06 1:04 

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.


Advertise | Privacy |
Web04 | 2.8.170924.2 | Last Updated 21 Sep 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid