Numeral systems

시간 제한3초메모리 제한1024 MB

요약
각 K와 D에 대해, 십진값에서 D를 뺀 수가 십육진값을 나누어떨어지게 하는 K자리 표기를 모두 찾는다.
난이도

보통10점 중 6점

유형
완전 탐색, 수학, 구현
정답자
아직 제출이 없습니다

문제

Khodislav has learned that apart from the decimal numeral system, there exist other systems, such as the hexadecimal system. He is curious about the connection of the values of the same notation in these two systems. For instance, can a sequence of KK digits have its hexadecimal value divisible by its decimal value? Will anything change if we subtract a specified number DD from the decimal value of this notation?

A notation is a sequence of digits. Digits from 0 through 9 can be used in a notation: they belong both to the decimal and to the hexadecimal systems. A notation of a number cannot begin with the digit 0. The decimal value of a notation is the number resulting from interpreting the notation as a decimal number. The hexadecimal value of a notation is the number resulting from interpreting the notation as a hexadecimal number.

입력

The first line contains an integer TT --- the number of tests in the file (1≤T≤1001 \le T \le 100). It is followed by TT tests, one per line.

For each test, two integers are provided: KK --- the number of digits in the notation and DD --- the number to be subtracted from the decimal value (2≤K≤152 \le K \le 15, 0≤D≤1060 \le D \le 10^6).

출력

For each test, find all required notations. Notations are sequences of KK digits without leading zeroes, with the value of XX in the decimal system and the value of YY in the hexadecimal system, for which X>DX > D and YY is divisible by (X−D)(X - D) without remainder.

The answers to each test are printed in a single line. First, print the number of the found notations, followed by all found notations in the ascending order, separated by spaces.

힌트

In the first test, the notation 37950 means X=37950X = 37950 in the decimal system and Y=227664Y = 227664 in the hexadecimal system. We can see that Y=227664Y = 227664 is divisible by X−D=37944X-D = 37944 without remainder. Identically, for the notation 24990, Y=149904Y = 149904 is divisible by X−D=24984X-D = 24984, and for the notation 12510, Y=75024Y = 75024 is divisible by X−D=12504X-D = 12504.

예제1

  1. 예제 1

    입력
    4
    5 6
    2 0
    2 5
    2 21
    
    예상 출력
    3 12510 24990 37950
    0
    2 16 22
    4 22 24 34 96