Created
April 14, 2017 23:57
-
-
Save LuxXx/9fe93be53386df74c0d286b71b8bf472 to your computer and use it in GitHub Desktop.
Project Euler - Problem 16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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