Click here to Skip to main content

Algorithms

 
GeneralRe: Specify numbers as product of Primes? PinmemberIan Uy28-Jun-08 6:46 
GeneralRe: Specify numbers as product of Primes? PinmemberPaul Conrad28-Jun-08 7:11 
GeneralRe: Specify numbers as product of Primes? PinmemberRavi Bhavnani8-Aug-08 8:16 
GeneralRe: Specify numbers as product of Primes? Pinmembercp987628-Jun-08 21:27 
GeneralRe: Specify numbers as product of Primes? PinmvpLuc Pattyn29-Jun-08 3:42 
GeneralRe: Specify numbers as product of Primes? PinmemberMarkBrock27-Jun-08 19:46 
GeneralRe: Specify numbers as product of Primes? PinmemberPaul Conrad28-Jun-08 6:42 
GeneralRe: Specify numbers as product of Primes? PinmemberChandraRam2-Jul-08 23:49 
GeneralRe: Specify numbers as product of Primes? PinmemberMarkBrock3-Jul-08 0:06 
AnswerRe: Specify numbers as product of Primes? PinmemberMember 419459326-Jun-08 9:19 
GeneralRe: Specify numbers as product of Primes? PinmemberRobert.C.Cartaino26-Jun-08 9:47 
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 
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] 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 
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 
GeneralRe: Factorials Pinmembercp987625-Jun-08 3:40 
AnswerRe: Factorials Pinmembertim_one14-Jul-08 9:37 
AnswerRe: Factorials PinmemberArash Partow25-Jun-08 3:14 
GeneralRe: Factorials PinmemberIan Uy25-Jun-08 7:26 
QuestionHow to determine the next x,y coordinate for a tank in a 2-D game... PinmemberEdmundisme18-Jun-08 9:35 
AnswerRe: How to determine the next x,y coordinate for a tank in a 2-D game... Pinmember73Zeppelin18-Jun-08 12:38 
GeneralRe: How to determine the next x,y coordinate for a tank in a 2-D game... PinmemberMatthew Butler18-Jun-08 12:44 
GeneralRe: How to determine the next x,y coordinate for a tank in a 2-D game... Pinmember73Zeppelin18-Jun-08 23:00 
GeneralRe: How to determine the next x,y coordinate for a tank in a 2-D game... PinmemberEdmundisme18-Jun-08 13:00 
AnswerRe: How to determine the next x,y coordinate for a tank in a 2-D game... PinmemberMatthew Butler18-Jun-08 12:41 
GeneralRe: How to determine the next x,y coordinate for a tank in a 2-D game... PinmemberEdmundisme18-Jun-08 13:01 
JokeRe: How to determine the next x,y coordinate for a tank in a 2-D game... PinmvpCPallini18-Jun-08 22:19 
QuestionPolyline offset algorithm Pinmemberbeko16-Jun-08 22:59 
AnswerRe: Polyline offset algorithm PinmemberAlan Balkany17-Jun-08 5:07 

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
Web01 | 2.8.150301.1 | Last Updated 2 Mar 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid