Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2007
    Thanked 0 Times in 0 Posts

    [C/C++] Output repeating numbers as n^b

    I am trying to take my output for a prime number say for example for the number 135 I get 3 3 3 5 and I would like to output it as 3^3 5. Another example would be 612 which I would want to output as 2^2 3^2 17.
    I am just looking for a pointer in the right direction. I want to code this myself.

  • #2
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Thanked 31 Times in 29 Posts
    It's a bit difficult to get you started on this problem without also getting you finished, as the solution is very short. But, to be vague:

    Handle one factor at a time, beginning by taking out as many 2s from the input number as you can and then working up with the remainder.

    Make use of modulus (% operator) to test whether one number is a factor of another


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts