0% found this document useful (0 votes)
20 views

Prob Base

The document describes a problem to write a program that converts integers from decimal to other bases. The input will consist of lines with two integers - a number n and a base b. The program should output n written in base b, with each digit separated by a space and without leading zeroes. Examples of conversions from decimal to binary and from decimal to a custom base are provided.

Uploaded by

Abdulwahid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Prob Base

The document describes a problem to write a program that converts integers from decimal to other bases. The input will consist of lines with two integers - a number n and a base b. The program should output n written in base b, with each digit separated by a space and without leading zeroes. Examples of conversions from decimal to binary and from decimal to a custom base are provided.

Uploaded by

Abdulwahid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Converting bases

There are lots of .base systems to represent numbers. Humans use decimal system
to read and write numbers, computers use binary system to store numbers. In this
problem, we are going to use base 𝑏.
Given integers 𝑛 and 𝑏, please write a program that converts an integer 𝑛 (given
in decimal format) in base 𝑏.

Input
Your input consists of an arbitrary number of lines, but no more than 1,000.
Each line contains two integers 𝑛 (1 ≤ 𝑛 ≤ 10&' ) and 𝑏 (2 ≤ 𝑏 ≤ 10&' ).
The end of input is indicated by a line containing only the value −1.

Output
For each input line, print the number 𝑛 written in base 𝑏. Each digit of the base-
𝑏 representation of 𝑛 should be written as an integer from 0 to (𝑏 − 1), and
should be separated by a space. Refer to the examples for good understanding.
The first integer for each output line should not be 0. (Do not print leading zeroes)

Example
Standard input Standard output
17 2 1 0 0 0 1
17 8 2 1
19990121 1999 5 5 121
1000000000000000000 4391 2689 4227 185 2713 386
-1
Time Limit
1 second.

You might also like