The rule is as follows:
- If the numeral ends in один/одна/одно, the noun complement is in the singular nominative: одно яблоко, двадцать одно яблоко
- If the numeral ends in два/две, три, четыре, the noun complement is in the singular genitive: два яблока, тридцать три яблока
- Otherwise, the noun complement is in the plural genitive: восемь яблок, пятнадцать яблок, сорок яблок.
Here's the algorithm:
- If the last two digits of the number are between 11 to 19, inclusive, then pl. gen., else
- If the last digit of the number is 1, then sg. nom., else
- If the last digit of the number is from 2 to 4, inclusive, then sg. gen., else
- Pl. gen.