Skip to content

Instantly share code, notes, and snippets.

@LuxXx
Created April 14, 2017 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LuxXx/9fe93be53386df74c0d286b71b8bf472 to your computer and use it in GitHub Desktop.
Save LuxXx/9fe93be53386df74c0d286b71b8bf472 to your computer and use it in GitHub Desktop.
Project Euler - Problem 16
package euler;
import java.math.BigInteger;
public class BigPow {
public static void main(String[] args) {
BigInteger n = BigInteger.valueOf(2).pow(1000);
System.out.println(sum(n.toString()));
}
public static int sum(String s) {
int sum = 0;
for (int i = 0; i < s.length(); i++) {
sum += s.charAt(i) - 48;
}
return sum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment