시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 4 MB 753 207 157 30.485%

문제

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+XHVjNjA4XHViOTdjIFx1YjRlNFx1YzViNCw8XC9wPlxyXG5cclxuPHVsPlxyXG5cdDxsaT43ODI5PHN1Yj4xMDxcL3N1Yj4gbW9kIDkgPSA4PFwvbGk+XHJcblx0PGxpPjM3Nz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lIGxpbWl0ZWQgdG8gMTAsMDAwLDAwMDxcL3A+XHJcbiIsIm91dHB1dCI6IjxwPkZvciBlYWNoIGRhdGEgc2V0IHRoZXJlIGlzIGEgc2luZ2xlIGxpbmUgb2Ygb3V0cHV0LiBJdCBjb250YWlucyB0aGUgZGF0YSBzZXQgbnVtYmVyIGZvbGxvd2VkIGJ5IGEgc2luZ2xlIHNwYWNlIHdoaWNoIGlzIHRoZW4gZm9sbG93ZWQgYnkgdGhlIHJlbWFpbmRlciByZXN1bHRpbmcgZnJvbSBkaXZpZGluZyBEIGJ5IChCIC0gMSkuPFwvcD5cclxuIiwiaGludCI6IiIsIm9yaWdpbmFsIjoiMSIsInByb2JsZW1fbGFuZ19jb2RlIjoiXHVjNjAxXHVjNWI0In1d

출처

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

  • 문제를 번역한 사람: baekjoon
  • 문제의 오타를 찾은 사람: sky1357