시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 (하단 참고) 4 MB 668 189 141 31.757%

문제

b진법 수가 주어졌을 때, 이를 b-1로 나눈 나머지를 출력하는 프로그램을 작성하시오.

예를 들어,

782910 mod 9 = 8

377777777777777738 mod 7 = 6

1234567 mod 6 = 3

(377777777777777738 = 112589990684261910, 1234567 = 2287510)

입력

첫째 줄에 테스트 케이스의 개수 T(1 ≤ T ≤ 1000)가 주어진다. 둘째 줄부터 T개의 줄에는 진법을 나타내는 B와 음이 아닌 수 B진법 수 D가 공백으로 구분되어 주어진다. (2 ≤ B ≤ 10) D는 최대 10,000,000자리이다.

출력

각각의 테스트 케이스에 대해서, B진법 수 D를 B-1로 나눈 나머지를 출력한다.

예제 입력 1

5
10 7829
7 123456
6 432504023545112
8 37777777777777773
2 10110100010101010101101110001010001010101010101010111

예제 출력 1

8
3
1
6
0
W3sicHJvYmxlbV9pZCI6IjM5NDQiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWIwOThcdWJhMzhcdWM5YzAgXHVhY2M0XHVjMGIwIiwiZGVzY3JpcHRpb24iOiI8cD5iXHVjOWM0XHViYzk1IFx1YzIxOFx1YWMwMCBcdWM4ZmNcdWM1YjRcdWM4NGNcdWM3NDQgXHViNTRjLCBcdWM3NzRcdWI5N2MgYi0xXHViODVjIFx1YjA5OFx1YjIwOCZuYnNwO1x1YjA5OFx1YmEzOFx1YzljMFx1Yjk3YyBcdWNkOWNcdWI4MjVcdWQ1NThcdWIyOTQgXHVkNTA0XHViODVjXHVhZGY4XHViN2E4XHVjNzQ0IFx1Yzc5MVx1YzEzMVx1ZDU1OFx1YzJkY1x1YzYyNC48XC9wPlxyXG5cclxuPHA+XHVjNjA4XHViOTdjIFx1YjRlNFx1YzViNCw8XC9wPlxyXG5cclxuPHA+NzgyOTxzdWI+MTA8XC9zdWI+IG1vZCA5ID0gODxcL3A+XHJcblxyXG48cD4zNzc3Nzc3Nzc3Nzc3Nzc3M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AwPFwvcD5cclxuIiwib3V0cHV0IjoiPHA+Rm9yIGVhY2ggZGF0YSBzZXQgdGhlcmUgaXMgYSBzaW5nbGUgbGluZSBvZiBvdXRwdXQuIEl0IGNvbnRhaW5zIHRoZSBkYXRhIHNldCBudW1iZXIgZm9sbG93ZWQgYnkgYSBzaW5nbGUgc3BhY2Ugd2hpY2ggaXMgdGhlbiBmb2xsb3dlZCBieSB0aGUgcmVtYWluZGVyIHJlc3VsdGluZyBmcm9tIGRpdmlkaW5nIEQgYnkgKEIgLSAxKS48XC9wPlxyXG4iLCJoaW50IjoiIiwib3JpZ2luYWwiOiIxIiwicHJvYmxlbV9sYW5nX2NvZGUiOiJcdWM2MDFcdWM1YjQifV0=

출처

ACM-ICPC > Regionals > North America > Greater New York Region > 2012 Greater New York Programming Contest B번

  • 문제를 번역한 사람: baekjoon
  • 시간 제한을 수정한 사람: jh05013
  • 문제의 오타를 찾은 사람: sky1357

시간 제한 안내

아래 적혀있지 않은 시간 제한은 언어 도움말에 적혀있는 기준을 따른다.

  • Python 2: 20초
  • Python 3: 20초
  • PyPy: 20초
  • PyPy3: 20초