In ancient Rome a numeric system was used for the representation of integers, that employed combinations of letters from the Latin alphabet to signify values. This numeric system was not a positional system, but an additive system in which the value of the represented number is determined by the sum of the composing symbols. The numbers 1 to 10 can be expressed in Roman numerals as follows: I, II, III, IV, V, VI, VII, VIII, IX en X. Negative numbers and zero can not be represented in the Roman numeric system. From the 14th century on, Roman numerals began to be replaced by the more convenient Arabic numerals. However, this process was gradual, and the use of Roman numerals in some minor applications continues to day as in names of kings (e.g. Louis XIV of France), in numbering schemes for annual events, and in numbering centuries in some countries (e.g. XIXe siècle).
Roman numerals, as used today, are based on seven symbols:
symbol | value |
---|---|
I | 1 |
V | 5 |
X | 10 |
L | 50 |
C | 100 |
D | 500 |
M | 1000 |
Numbers are formed by combining symbols together and adding the values, but the order of the symbols is important too. Symbols are placed from left to right in order of value, starting with the largest. However, in a few specific cases, in order to avoid characters being repeated in succession (such as IIII or XXXX)1, these can be reduced using subtractive notation. In case a symbol is preceded by another symbol with a lower value, the lower value is subtracted from the higher value to give the value in the addition. In ancient times, the rules for writing Roman numerals have been very loose. As such, the BBC used the typographical more elegant MIM instead of MCMCIX in its subtitles to represent the year 1999.
The decimal representation of the number $$n \in \mathbb{N}$$ (using Arabic numerals).
The number $$n$$ represented using Roman numerals (uppercase only). The
conversion of Arabic to Roman numerals can be done by traversing the table
below from left to right. As long as the value $$n$$ is greater or equal
to the integer value in the table, you append the combination of Roman
numerals on the corresponding position to the Roman number. Afterwards,
the value of $$n$$ is decremented with the integer value. As soon as $$n$$
is smaller than the integer value from the table, you step one position to
the right in the table.
M | CM | D | CD | C | XC | L | XL | X | IX | V | IV | I |
1000 | 900 | 500 | 400 | 100 | 90 | 50 | 40 | 10 | 9 | 5 | 4 | 1 |
The above procedure allows to uniquely convert the decimal representation
of an integer into a representation using Roman numerals.
Input:
1999
Output:
MCMXCIX