Assuming 100 grams of the compound, we can convert the masses to the number of moles using the atomic masses:
53.5 g * 1 mol C / 12.0107 g C = 4.45 mol C
15.5 g * 1 mol H / 1.00794 g H = 15.38 mol H
31.1 g * 1 mol N / 14.0067 g N = 2.22 mol N
We divide the number of moles of each element by the lowest number of moles, in this case, we divide by 2.22:
C 4.45/2.22 = 2.00
H 15.38/2.22 = 6.93 ≈ 7
N 2.22/2.22 = 1
Therefore we can write the empirical formula using the number of moles calculated as the subscript for each element: C2H7N