View Full Version : [C/C++] Output repeating numbers as n^b

Crackerjack

10-08-2007, 02:04 AM

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.

ralph l mayo

10-09-2007, 03:03 AM

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

Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.