Logo
(追記) (追記ここまで)

5228번 - Base K 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB158513730.081%

문제

We are now used to the decimal positional notation for representing numbers, the modern version of which only dates back to the 9th century. In this notation we use 10 digits, from 0 to 9, to represent a number. However there is nothing special about 10, and we can just as easily use any other base to represent numbers. For example, in base-2 (binary) notation, we only use 2 digits, 0 and 1, whereas in base-16 (hexadecimal) notation, we use 15 digits: 0-9, a, b, c, d, e, f (the last 6 representing the digits ten, eleven, twelve, thirteen, fourteen, and fifteen); both these notations are commonly used by computers. In fact, several other bases are commonly seen in history: base-60 (used by ancient Babylonians), base-13 (used by Mayans), base-20 (Aztecs and Mayans, and possibly old Europe), base-27 (Telefol language and the Oksapmin language), and so on.

More generally, a base-$k$ representation uses $k$ digits: 0ドル$ to $k - 1$. Given a number $n$ represented in base-$k$ as $a_3a_2a_1a_0,ドル where $a_3,ドル $a_2,ドル $a_1,ドル $a_0$ are digits, we have that: $$n = (a_3a_2a_1a_0)_k = a_3 \times k^3 + a_2 \times k^2 + a_1 \times k^1 + a_0 \times k^0$$

Here we use the subscript $k$ to denote that the number is being written in base-$k$.

For example,

  • 465ドル_7 = 4 \times 7^2 + 6 \times 7^1 + 5 \times 7^0 = 243_{10}$
  • 46ドルE_{16} = 4 \times 16^2 + 6 \times 16^1 + 14 \times 16^0 = 1134_{10}$ (recall $E$ represents the number fourteen in base-16)

Our use of decimal notation is likely based on it being easier to count up to 10 using fingers. However, programs have no such restriction. When Sam arrives on the Grid world, he discovers that the programs use arbitrary bases to communicate numbers to each other. Sam, not really being a program, has serious trouble with this, and practices arithmetic in arbitrary bases as much as he can. For example, when he sees any two numbers written together, call them $n$ and $k,ドル he times how long it takes him to decide whether base-$k$ representation of n contains all digits from 0ドル$ to $k − 1$.

For example, base-3 representation of fifteen $(15_{10})$ is 120ドル_3$: $120ドル_3 = 1 \times 3^2 + 2 \times 3^1 + 0 \times 3^0 = 9 + 6 + 0 = 15_{10}$$

which contains all 3 digits. In comparison, base-4 representation of eighteen $(18_{10})$ is 102ドル_4$: $102ドル_4 = 1 \times 4^2 + 0 \times 4^1 + 2 \times 4^0 = 16 + 0 + 12 = 18_{10}$$

does not contain all 4 digits (it only contains 0, 1, and 2).

You are to write a program to help Sam verify his answers, i.e., given two numbers $n$ and $k,ドル you are to decide if base-$k$ representation of $n$ contains all digits from 0ドル$ to $k - 1$. Note that the digit 0 must appear somewhere in the middle of the number; so the number 123456789 in base-10 representation does NOT contain all digits (it only contains 1-9, but no 0, even though we can also write the number as 0123456789).

입력

The first line in the test data file contains the number of test cases (< 100). After that, each line contains one test case, i.e., two numbers $n$ and $k,ドル in that order. Assume that 2ドル \le k \le 30,ドル and 0ドル \le n < 2^{30}$.

출력

The output is shown with an extra blank line so that each test case input is aligned with the output; that blank line should not be present in the actual output.

제한

출력 형식

정확한 출력 형식은 제출에서 언어를 Java로 설정하면 확인할 수 있다.

예제 입력 1

6
100 10
343 7
240 5
1234567890 10
1 2
2 2

예제 출력 1

Base-10 representation of 100 is 100; does not contain all digits.
Base-7 representation of 343 is 1000; does not contain all digits.
Base-5 representation of 240 is 1430; does not contain all digits.
Base-10 representation of 1234567890 is 1234567890; contains all digits.
Base-2 representation of 1 is 1; does not contain all digits.
Base-2 representation of 2 is 10; contains all digits.

힌트

출처

School > University of Maryland High School Programming Contest > HSPC 2011 1번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /