Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have just tried <a href="http://docs.oracle.com/javase/1.4.2/docs/api/java/math/BigInteger.html" rel="nofollow">BigInteger</a> in Java and it works.</p> <p>Working code for demonstration purpose:</p> <pre><code>import java.math.BigInteger; public class Factorial { public static int[] primes = {2,3,5,7,11,13,17,19,23,29,31,37}; public static BigInteger computeFactorial(int n) { if (n==0) { return new BigInteger(String.valueOf(1)); } else { return new BigInteger(String.valueOf(n)).multiply(computeFactorial(n-1)); } } public static String getPowers(int n){ BigInteger input = computeFactorial(n); StringBuilder sb = new StringBuilder(); int count = 0; for (int i = 0; i &lt; primes.length &amp;&amp; input.intValue() != 1;) { BigInteger[] result = input.divideAndRemainder(new BigInteger(String.valueOf(primes[i]))); if (result[1].intValue() == 0) { input = input.divide(new BigInteger(String.valueOf(primes[i]))); count++; if (input.intValue() == 1) {sb.append(primes[i] + "(" + count + ") ");} } else { if (count!=0) sb.append(primes[i] + "(" + count + ") "); count = 0; i++; } } return sb.toString(); } public static void main(String[] args) { System.out.println(getPowers(37)); } } </code></pre> <p>Feel free to use it without worrying about copyright if you want.</p> <p><strong>Update</strong>: I didn't realize you were using C++ until now. In that case, you can give <a href="http://code.google.com/p/cpputils/source/browse/0.6/cpputils/include/cpputils/exttypes/BigInteger.hpp?r=c62b5ae5ec96fa6373805e96c52397f853ec8a5e" rel="nofollow">boost BigInteger</a> a try.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload