You are viewing a single comment's thread. Return to all comments →
Java8
public static int sumDigit(BigInteger n) { int count = 0; while (n.compareTo(BigInteger.ZERO) > 0) { count += n.mod(BigInteger.TEN).intValue(); n = n.divide(BigInteger.TEN); } return count; } public static void main(String[] args) { Scanner s = new Scanner(System.in); int testcase = s.nextInt(); for (int i = 0; i < testcase; i++) { int n = s.nextInt(); BigInteger res = BigInteger.valueOf(2).pow(n); System.out.println(sumDigit(res)); } s.close(); }
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #16: Power digit sum
You are viewing a single comment's thread. Return to all comments →
Java8