Build a Mass Spectrometer! Challenge

Given the high resolution molecular mass of an organic molecule, output the molecule's molecular formula.

Explanation

The input will be a single number to three decimal places of precision, the relative molecular mass of the molecule.

Here, the molecular mass is defined as the sum of the masses of the atoms in the compound. Since you only are finding the molecular formulae of organic compounds, the atomic masses you need to know are:


C, Carbon: 12.011
H, Hydrogen: 1.008
O, Oxygen: 15.999
N, Nitrogen: 14.007


Your formula should only ever contain carbon, hydrogen, oxygen or nitrogen.

When writing the formula, it should take the form:

CaHbOcNd


Where the elements must be in that order (C -&gt; H -&gt; O -&gt; N, so C2O8N4H6 should be C2H6O8N4) and a, b, c and d are numbers of the preceding element in the molecule (i.e. C2 means that there are two carbon atoms in the molecule).

If a, b, c or d are zero, that element should not be included in the formula (e.g. C2H6O2N0 should be C2H6O2). Finally, if a, b, c or d are one, you should not include the number in the formula (e.g. C1H4 should be CH4).

The input will always be valid (i.e. there will be a molecule with that mass). If the input is ambiguous (multiple molecules have the same mass), you must only output one of the molecules. How you choose this molecule is up to you.

Worked Example

Suppose the input is 180.156, there is only one combination of the elements which can have this molecular mass:

12.011*6 + 1.008*12 + 15.999*6 + 14.007*0 = 180.156


So there are:


6 Carbons
12 Hydrogens
6 Oxygens
0 Nitrogens


Therefore, your output should be:

C6H12O6


More Examples

Input -&gt; Output

28.054 -&gt; C2H4
74.079 -&gt; C3H6O2
75.067 -&gt; C2H5O2N
18.015 -&gt; H2O


Winning

Shortest code in bytes wins.
Mathematica, 108 bytes

Print@@Join@@({Characters@"CHON",#}ᵀ/.a_/;Last@a&lt;2:&gt;Table@@a)&amp;/@{12011,1008,15999,14007}~FrobeniusSolve~#&amp;


Pure function expecting the input as an integer (1000 times the relative molecular mass); it prints all possible answers to STOUD (and returns an array of Nulls).

The heavy lifting is done by the builtin {12011,1008,15999,14007}~FrobeniusSolve~#, which finds all nonnegative integer combinations of the hardcoded weights that equal the input. {Characters@"CHON",#}ᵀ puts each such combination in a form like {{"C", 0}, {"H", 1}, {"O", 2}, {"N", 3}}. (ᵀ is actually the 3-byte private Mathematica character U+F3C7.)

The transformation rule /.a_/;Last@a&lt;2:&gt;Table@@a changes pairs of the form {x, 0} to {} and pairs of the form {x, 1} to {x} (and spits out errors as it tries to apply to the whole expression as well). Then Print@@Join@@ prints the result in the correct form, avoiding the need to cast the integers as strings and concatenate.