Click here to Skip to main content
15,888,351 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Specify numbers as product of Primes? Pin
Paul Conrad28-Jun-08 5:42
professionalPaul Conrad28-Jun-08 5:42 
GeneralRe: Specify numbers as product of Primes? Pin
ChandraRam2-Jul-08 22:49
ChandraRam2-Jul-08 22:49 
GeneralRe: Specify numbers as product of Primes? Pin
MarkB7772-Jul-08 23:06
MarkB7772-Jul-08 23:06 
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 
A possible solution would be as follows:
void prime_factors(unsigned int n, std::deque<std::pair<unsigned int,unsigned int>>& factor_list)
{
   factor_list.clear();

   unsigned int upper_bound = ::floor(std::sqrt(n));
   unsigned int i = 2;
   while(i <= upper_bound)
   {
      std::pair<unsigned int, unsigned int> current_factor(i,0);
      while(0 == (n % i))
      {
         n /= i;
         ++current_factor.second;
      }
      if (current_factor.second > 0)
      {
         factor_list.push_back(current_factor);
      }
      ++i;
   }
}

The prime-factors will be in the deque, the first of each element is the factor and the second is the recurrence count of the factor.

[updated]
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 
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 

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.