School informatics
시간 제한3초메모리 제한1024 MB
알파벳 크기 N, 메시지 길이 L, 그룹 크기 상한 K가 주어질 때, 패딩을 포함한 전체 비트 수를 최소로 하는 그룹 크기 B를 각 테스트마다 구한다.
문제
Vasya was getting ready for his SAT tests in Informatics and found the following problem in one of his textbooks: "All books stored in the library have the same format. A book contains pages, each page contains lines, and there are precisely printed symbols in a line. There are different symbols: letters, period, comma and space. Calculate the number of bits necessary to encode the contents of a single book."
Vasya decided that the authors of the problem assumed that all symbols must be coded with the same number of bits. Thus, to code different symbols one must use bits per symbols. But such coding means storing unnecessary information.
Had it been known that different symbols and their combinations occur in text with different frequency, using variable-length code would make sense, e.g. Huffman code. But the authors hadn't provided the necessary information, so Vasya assumed all symbols and their combinations occur in the text with equal frequency, and used a fixed number of bits for coding.
Vasya gave it another thought and realized that coding groups of symbols instead of single symbols could allow to partially get rid of the useless information.
For example, when coding groups of three subsequent symbols, the number of possible combinations would be . Then bits is enough to encode this number of combinations. This way we get bits per symbol instead of as the authors assumed.
Vasya wondered if this was a way to indefinitely approach the value . But then he remembered that the code was intended for use with finite-length messages. If the length of a message is not divisible by the length of the letter groups being coded, the message is automatically padded with spaces until number of letter groups becomes integer. Moreover, the use of excessively long letter groups is impossible due to technical reasons.
Vasya decided to write a program which would define the optimal size of letter group for coding messages with predefined parameters. Help Vasya write the program.
입력
The first line of the input file contains the integer number --- the number of tests (). This is followed by the test descriptions, one test per line.
For each test, three integer numbers are provided: --- the number of different symbols in the message alphabet, --- the message length in symbols, and --- the maximum allowed letter group size (, , ).
For each test it is guaranteed that the number either is an integer, or differs from any rational number with a denominator no greater than by at least .
출력
For each test, print a separate line containing two integers: --- the resulting length of the coded message in bits and --- the size of the letter group used ().
The length of the coded message must be as short as possible, provided that the length of the letter group is no greater than the number (defined in the input data). If there are several optimal solutions, any of them can be printed.
힌트
The first test corresponds to the example from Vasya's textbook: the message is symbols long, and the alphabet contains symbols. In the given case, the use of three-letter groups provides the minimal size of the encoded message, if letter group size is kept within . One space is automatically added at the end of the message due to padding. If each symbol was coded separately, as originally intended by the textbook authors, bits of information would be required.