Created
January 9, 2019 23:25
-
-
Save ClearNB/4559f064af51c376b1f48470105a2dde to your computer and use it in GitHub Desktop.
Power digit sum (Java 8 ver) Sample by ClearNB
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
import java.math.BigInteger; | |
import java.util.*; | |
public class Solution { | |
static int getValue(String data) { | |
int res = 0; | |
for(int i = 0; i < data.length(); i++) { | |
res += Integer.parseInt(data.substring(i, i + 1)); | |
} | |
return res; | |
} | |
public static void main(String[] args) { | |
try (Scanner sc = new Scanner(System.in)) { | |
int T = sc.nextInt(); | |
for(int a0 = 0; a0 < T; a0++) { | |
int N = sc.nextInt(); | |
BigInteger bi = BigInteger.ONE; | |
for(int i = 0; i < N; i++) { | |
bi = bi.multiply(BigInteger.valueOf(2)); | |
} | |
String str = "" + bi; | |
int sum = getValue(str); | |
System.out.println(bi + " : " + sum); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment