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

33018번 - Divisibility Test 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 2048 MB31262191.304%

문제

Daisy has recently learned divisibility rules for integers and she is fascinated by them. One of the tests she learned is a divisibility test by 3. You can find a sum of all digits of a decimal number and check if the resulting sum is divisible by 3. Moreover, the resulting sum of digits is congruent modulo 3 to the original number --- the remainder modulo 3 is preserved. For example, 75ドル \equiv 7 + 5 \pmod 3$. Daisy is specifically interested in such remainder preserving divisibility tests.

There are more examples like that that she learned for decimal integers (integers base 10):

  • To test divisibility modulo 11, find an alternating sum of digits. Counting digits from the last (least significant) digit, add digits on odd positions (the last, 3rd to the last, etc) and subtract digits on even positions (2nd to the last, 4th to the last, etc) to get the sum that is congruent modulo 11 to the original number. For example, 123ドル \equiv 1 - 2 + 3 \pmod {11}$.
  • To test divisibility modulo 4, keep the last two digits. Their value is congruent modulo 4 to the original number. For example, 876543ドル \equiv 43 \pmod 4$.
  • To test divisibility modulo 7, find an alternating sum of groups of three digits. For example, 4389328ドル \equiv 4 - 389 + 328 \pmod 7$.

Similar tests can be found in other bases. For example, to test divisibility modulo 5 for octal numbers (base 8), find an alternating sum of groups of two digits. For example, 1234ドル_8 \equiv -12_8 + 34_8 \pmod 5$.

Daisy wants to find such rules for a given base $b$. She is interested in three kinds of divisibility rules:

  • Kind 1 --- take the last $k$ digits of an integer in base $b$.
  • Kind 2 --- take a sum of groups of $k$ digits of an integer in base $b$.
  • Kind 3 --- take an alternating sum of groups of $k$ digits of an integer in base $b$.

It is not always possible to find such a divisibility rule. For example, in base 10 there is no such test for divisibility modulo 6, even though different approaches to testing divisibility by 6 exist.

Given base $b$ and modulo $n,ドル Daisy wants to know the smallest group size $k$ for which such a divisibility test exits.

입력

There are several tests in the input. The first line of the input contains an integer $t$ --- the number of tests. The next $t$ lines describe the tests.

Each test consists of a line with two integers $b$ and $n$ --- the base and the modulo ($b, n \ge 2$). The sum of all $b$ values in the input does not exceed 10ドル^6,ドル and the sum of all $n$ values in the input does not exceed 10ドル^6$.

출력

Write $t$ lines --- a line for each test in the input. On a line for a test write a single integer 0ドル$ if the divisibility test for a given $b$ and $n$ does not exist. Otherwise, write two integers $a$ and $k,ドル where $a$ is the kind of the divisibility test (1, 2, or 3) and $k$ is the number of digits in a group for the test, such that $k$ is the lowest among all possible divisiblity tests for the given $b$ and $n$.

제한

예제 입력 1

6
10 3
10 11
10 4
10 7
8 5
10 6

예제 출력 1

2 1
3 1
1 2
3 3
3 2
0

힌트

출처

ICPC > Regionals > Northern Eurasia > Northern Eurasia Finals > Northern Eurasia Finals 2023 D번

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

출처

대학교 대회

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

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