Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is my solution:</p> <pre><code>public static void main(String[] args) { ArrayList&lt;Integer&gt; n = myPow(2, 100); int result = 0; for (Integer i : n) { result += i; } System.out.println(result); } public static ArrayList&lt;Integer&gt; myPow(int n, int p) { ArrayList&lt;Integer&gt; nl = new ArrayList&lt;Integer&gt;(); for (char c : Integer.toString(n).toCharArray()) { nl.add(c - 48); } for (int i = 1; i &lt; p; i++) { nl = mySum(nl, nl); } return nl; } public static ArrayList&lt;Integer&gt; mySum(ArrayList&lt;Integer&gt; n1, ArrayList&lt;Integer&gt; n2) { ArrayList&lt;Integer&gt; result = new ArrayList&lt;Integer&gt;(); int carry = 0; int max = Math.max(n1.size(), n2.size()); if (n1.size() != max) n1 = normalizeList(n1, max); if (n2.size() != max) n2 = normalizeList(n2, max); for (int i = max - 1; i &gt;= 0; i--) { int n = n1.get(i) + n2.get(i) + carry; carry = 0; if (n &gt; 9) { String s = Integer.toString(n); carry = s.charAt(0) - 48; result.add(0, s.charAt(s.length() - 1) - 48); } else result.add(0, n); } if (carry != 0) result.add(0, carry); return result; } public static ArrayList&lt;Integer&gt; normalizeList(ArrayList&lt;Integer&gt; l, int max) { int newSize = max - l.size(); for (int i = 0; i &lt; newSize; i++) { l.add(0, 0); } return l; } </code></pre> <p>This code can be improved in many ways ... it was just to prove you can perfectly do it without BigInts.</p> <p>The catch is to transform each number to a list. That way you can do basic sums like:</p> <pre><code>123456 + 45 ______ 123501 </code></pre>
 

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