It has to do with the cases. I've seen the following in other comments here, and please forgive any errors!, but this is what I've got:
1, or numbers ending in 1: nominative singular (одни рік)
2-4, or numbers ending in 2/3/4 in Ukrainian wording: nominative plural (два року)
5+, or numbers ending in 5+ in Ukrainian wording: genitive plural (шість років)
This goes by the last -word- instead of number, e.g., 24 року, not «років»
I hope this helps!