Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* package codechef; // don't place package name! */
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.InputMismatchException;
- import java.util.Map;
- import java.util.Set;
- /* Name of the class has to be "Main" only if the class is public. */
- public class Main {
- public static void main(String[] args) throws IOException {
- final InputReader reader = new InputReader(System.in);
- int t = reader.readInt();
- StringBuilder sb = new StringBuilder();
- for (int tItr = 0; tItr < t; tItr++) {
- long k = reader.readLong();
- long result = getDistinceDigitUpToK(k);
- sb.append(result).appendCodePoint('\n');
- }
- System.out.print(sb.toString());
- reader.close();
- }
- private static long getDistinceDigitUpToK(long k) {
- Map<Long, Long> map = new HashMap<Long, Long>();
- long limit = (long) Math.pow(10, k);
- for (long i = 0; i < limit; i++) {
- long signFront = i;
- long signBack = limit - i - 1;
- long digitCount = getDigitCount(signFront, signBack);
- Long count = map.getOrDefault(digitCount, 0L);
- map.put(digitCount, count + 1);
- }
- return map.get(2L);
- }
- private static long getDigitCount(long signFront, long signBack) {
- Set<Long> set = new HashSet<Long>();
- if (signFront == 0 || signBack == 0) {
- set.add(0L);
- }
- while (signFront > 0) {
- long digit = signFront % 10;
- set.add(digit);
- signFront = signFront / 10;
- }
- while (signBack > 0) {
- long digit = signBack % 10;
- set.add(digit);
- signBack = signBack / 10;
- }
- return set.size();
- }
- }
- class InputReader {
- private final InputStream stream;
- private final byte[] buf = new byte[1024];
- private int curChar;
- private int numChars;
- public InputReader(InputStream stream) {
- this.stream = stream;
- }
- public int read() {
- if (numChars == -1)
- throw new InputMismatchException();
- if (curChar >= numChars) {
- curChar = 0;
- try {
- numChars = stream.read(buf);
- } catch (IOException e) {
- throw new InputMismatchException();
- }
- if (numChars <= 0)
- return -1;
- }
- return buf[curChar++];
- }
- public int readInt() {
- int c = read();
- while (isSpaceChar(c))
- c = read();
- int sgn = 1;
- if (c == '-') {
- sgn = -1;
- c = read();
- }
- int res = 0;
- do {
- if (c < '0' || c > '9')
- throw new InputMismatchException();
- res *= 10;
- res += c - '0';
- c = read();
- } while (!isSpaceChar(c));
- return res * sgn;
- }
- public boolean isSpaceChar(int c) {
- return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
- }
- public String readString() {
- int c = read();
- while (isSpaceChar(c))
- c = read();
- StringBuilder res = new StringBuilder();
- do {
- res.appendCodePoint(c);
- c = read();
- } while (!isSpaceChar(c));
- return res.toString();
- }
- public long readLong() {
- int c = read();
- while (isSpaceChar(c))
- c = read();
- int sgn = 1;
- if (c == '-') {
- sgn = -1;
- c = read();
- }
- long res = 0;
- do {
- if (c < '0' || c > '9')
- throw new InputMismatchException();
- res *= 10;
- res += c - '0';
- c = read();
- } while (!isSpaceChar(c));
- return res * sgn;
- }
- public void close() throws IOException {
- stream.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement