Different number systems


Plus
Pin


Problem description Progress
ID 21763. Maximum digit in octal ss
Темы: Different number systems   

Given a natural number N . It is necessary to find the maximum digit of the given number when it is written in the octal number system.

Input
The input is a natural number N (\(N<=255\)).

Imprint
Display the answer to the problem.
 

 

Examples
# Input Output
1 255 7

 

ID 30775. Easy calculation
Темы: Different number systems   

Natural number n is given. It is necessary to convert it to k-ary number system and find the difference between the product and the sum of its digits in this number system.
 
For example, let's say \(n = 239\), \(k = 8\). Then the representation of the number n in the octal system — \(357\) and the answer to the problem is \(3 \cdot 5 \cdot 7 ? (3 + 5 + 7) = 90\).
 
 
Input
String contains two natural numbers: n and k (\(1 <= n <= 10^9 \), \(2 <= k <= 10\)). Both of these numbers are given in decimal notation.
 
Output
Print the answer to the problem (in decimal notation).
 

 

Examples
# Input Output
1 239 8 90
2 1000000000 7 -34

ID 30776. Room simplification
Темы: Different number systems   

How can you not remember a 6 or 7 digit phone number that appears for a second on the TV screen?! With the help of a special technique described below, you will become a walking telephone directory!
 
Obviously, the number 402 is easier to remember than the number 110010010, and the number 337377 is easier to remember than the number 957472. So, on the one hand, it is necessary that the number to be remembered contains as few digits as possible, and on the other hand, it is desirable that the number had as many repeating digits as possible. As a criterion for the complexity of memorization, we will take the sum of the number of digits in the number and the number of different digits in the number. The memorized number can be written in a different number system, perhaps then it will be easier to remember. For example, the number 65535 looks like FFFF in hexadecimal.
Write a program for selecting the base of the number system to minimize the complexity criterion. The base of the number system must be chosen in the range from 2 to 36, then the numbers 0-9 and the English letters A-Z can be used to represent the number.
 
Input
The first line contains the integer n (\(1 <= n <= 100\)) in the first line. This is followed by n lines, each line containing an integer from 1 to 999999999.
 
Output
Response must contain n lines. For each of the n given numbers, the line contains: the base of the number system (from 2 to 36), which minimizes the memory difficulty criterion, and the number in the chosen number system, separated by one space. If several bases give the same value of the criterion, then choose the smallest among them.
 

 

Example
# Input Output
1
2
2
65535
3 2
16FFFF

ID 30774. Prize
Темы: Different number systems   

Despite the crisis, Soft-Soft is doing well. The director of the company decided to pay bonuses to employees. The list of the lucky ones was released the next day. In order not to disclose the amount of payments, strange numbers and even letters flaunted in front of the names on the list. Employees quickly guessed that the amount of bonuses was written in different number systems. But where and what number system is used, only secretary Tanechka figured out, who remembered that the director asked her to bring information about the age of employees. She realized that the headmaster was dropping the tens from the number indicating age, and adding the number 2 to the remaining ones. The resulting value served as the basis for presenting the accrued premium.
 
Help the curious Tanechka find out the amount of bonuses in decimal notation. It is known that the amount of premiums does not exceed 100,000 rubles in decimal notation.
 
Input
On the first line  two integers N and K – age and bonus amount separated by a space. The age does not exceed 100, the amount of the award is indicated in some number system (the number does not contain insignificant zeros, uses Arabic numerals and capital English letters).
 
Output
Print a single number – the amount of the premium in decimal notation.
 

 

Examples
# Input Output
1 28 2800 2800
2 30 101 5

ID 30779. Easy sorting
Темы: Different number systems   

Let x – a positive integer, and k – natural number from 1 to 10. Let s(x, k) be equal to the sum of the digits of the number x represented in base number system k.< /div>
 
Specified n numbers a1, a2, ..., an. It is necessary to calculate the sequence bi using the formula \(b_i = s(a_i, k_1) \cdot s(a_i, k_2)\ ). After that, sort the sequence bi in non-descending order.
 
Input
The first line contains three integers: n, k1, k2 (\(1 <= n <= 1000\), \(2 <= k_1, k_2 <= 10\)). The second line contains n integers: ai (\(1 <= a_i < = 10^9\)).
 
Output
In response, output n numbers – bi in the required order.
 

 

Examples
# Input Output
1
9 10 10
1 2 3 4 5 6 7 9 8
1 4 9 16 25 36 49 64 81
2
10 2 2
1 2 4 8 16 32 64 128 256 512
1 1 1 1 1 1 1 1 1 1

ID 33080. Homework
Темы: Different number systems   

Little Arseniy was given the following task at the number system circle: convert the number X in the number system s1 to the number system s2. Without thinking twice, he called his best friend Dobrynya for help, who was famous for being remarkably able to count to 10 on his fingers. After several sleepless nights, the guys coped with the task with common efforts.
 
However, at the next lesson, Arseniy was given a similar problem, where X, unfortunately, exceeded 10. Then the guys decided to apply to the Summer Computer School with a request to write a universal program that solves the problem for any X, s1 and s2. Your goal – fulfill the request of Arseniy and Dobrynya.
 
Input
Your program is given 3 numbers as input: the original number X, bases s1 and s2 (\(2 <= s1,\ s2 <= 10\)). The number X in decimal notation does not exceed \(2 \cdot 10^9\).
 
Output
The output should contain a single number equal to the number X in the number system s2, or -1 if the input is invalid.< br />
 

 

Examples
# Input Output
1 101 2 10 5
2 200 2 10 -1


 

ID 38280. martian zeros
Темы: Different number systems   

On Mars, the base k number system is used. Unlike the decimal number system we are used to, in this number system there are k digits with values ​​from 0 to k - 1 , and the weight of the digit in the i -th digit is equal to ki .

For example, let k = 8 . The entry 3578 means the number 3·8 2 + 5·8 + 7 , in the decimal number system more familiar to earthlings, this number is written as 23910 . And the number 19210 , in the number system with base 8 is written as 3008 .

Ildar — young Martian, and he is very fond of round numbers. Ildar calls a number sufficiently round if its notation in the number system with base k ends with at least n zeros. Today Ildar wants to find i -th in order sufficiently round number.

Help Ildar, find the i -th natural number that is sufficiently round in the number system with base k and output it in the decimal number system. Ildar is very friendly and guarantees that the answer in decimal not exceed 1018 .

Input
All restrictions on numbers in this problem are given in the decimal number system. All numbers in the input are also written in decimal notation.

The first line of the input contains the number k — the base of the number system used by Ildar ( 2 ≤ k ≤ 109 ).

The second line of the input contains the number n — the minimum number of zeros at the end of a sufficiently round number ( 0 ≤ n ≤ 100 ).

The third line of the input contains the number i — ordinal of a sufficiently round number that Ildar is interested in ( 1 ≤ i ≤ 109 ).

Imprint
Print one number — notation in decimal notation of the i-th in order sufficiently round in the number system with base k of a natural number. It is guaranteed that the answer does not exceed 1018 .

Note that the response may not fit in the standard 32-bit data type. It is necessary to use a 64-bit type, in pascal it is called « int64 ", in C++ " long long ", in Java " long ". If you're writing in Python, don't worry, Python's built-in integer type has no limits on the size of a number.
 

# Input Output
1 8
2
2
192

ID 38590. Binary to hexadecimal
Темы: Different number systems   

Write a program that converts a number from binary to hexadecimal

Input
The program receives as input a string consisting of zeros and ones, the length of which does not exceed 4000 characters. The first character of a string is always one. This string is a binary representation of some number.

Imprint
It is necessary to write in hexadecimal form and output this number using the numbers 0, ..., 9 and the letters A, ..., F without leading zeros.

Examples
# Input Output
1 10100 14

ID 39625. XOR
Темы: Number systems    Different number systems   

Exclusive "or" (XOR) is a Boolean function, as well as a logical and bitwise operation on two arguments, the result of which is true if and only if one of the arguments is true and the second is false.
Circular bit shift to the right - an operation in which the least significant digit is transferred to the beginning of the number and becomes the most significant, and all the rest are shifted to the right by one position.
To two 16-bit numbers A and B, written in hexadecimal notation, the  exclusive "or" operation was applied, and then to the result - the operation of a bitwise circular shift to the right by K bits. One of the two original numbers has been forgotten and needs to be restored.
Input
the numbers A, K and the result X are written into the string, separated by a space. The numbers A and X are given in the  hexadecimal number system, K - in decimal.
Imprint
B number.

Examples
# Input Output
1 1A2B 4 4E5D FFFF
2 AB00 1 5C9A 1234